Question: the coding Must be on MATLAB 1 % NOTE: Use variable name x for the x array 2 % NOTE: Use variable name tempSave for


the coding Must be on MATLAB
1 % NOTE: Use variable name x for the x array 2 % NOTE: Use variable name tempSave for the intermediate variable, 3 % Specifically for, 'Save the second element in a variable (you can call it anything, tempSave maybe?)' 4 5 %IMPORTANT!! 6 % Use this code for x instead of [10 13 12 14] or [8 10 9 11 12] when submitting 7 x = randi([0, 100], 1,4); 8 9 % xInitial used for grading purposes, do not use xInitial variable when completing lab 10 xInitial = x; Make an array x = [10 13 12 14). Now swap the 2nd and 3rd elements in the array so the numbers are in the right order; do not do this by making a new x! Edit the x array. Hint: You will need a temporary variable to accomplish this. Do not assume that you know the values in x; your code should if x was changed to [8 10 9 11) instead. Step by Step Instructions: Do the following on the command line, until you figure out the answer, then copy it into a script Create x with four elements as given. Set the second element to be 35 o Make sure you know how to set a specific element of an array Print out the third element to the command line o Make sure you know how to get the 3rd element Now set the second element to the third element Print out x to verify that the second element now has the value of the third Ok, that's half the problem... but... you now no longer have the second element around. Oops. Re-make x with the 4 elements. Save the second element in a variable (you can call it anything, tempSave maybe?) Set the second element to the third. Now - set the third element to the value that use to be in the second element o Where did you save it? Hint, see three lines above. Now do this in a script. Print out x at the start and the end (you can use dier to show x or just leave the semi-colon off) Repeat with x = [8 10 9 11 12] Self-check: Original 10 13 12 14 Swapped x = 10 12 13 14 [Repeat for other x array]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
