All parts needed. Will give thumbs up for correct answers. Problem 1: Array Inde
ID: 3877547 • Letter: A
Question
All parts needed. Will give thumbs up for correct answers. Problem 1: Array Indexing For this problem, you will need to download the HW1.mat file from Blackboard. Drop it in your current MATLAB folder then type: load HW1 at the MATLAB command prompt. You should now have the following three variables (x, y, and M) in your workspace with the values shown below. Don't make any modifications to these variables. x=45_1 53-20255-15534 y 1 5 5 4 5 3 -2 4 5 3 4 3 1 31 M2 24 -2 9 -5-5 -4-1 5 -3 2 2 -2 4 2 -4 3 For all parts of this problem, don 't put a semicolon at the end of your command so you can copy the results as well as your MATLAB command. a) What MATLAB command will pull out entries 7 thru 12 in vector, x, and store them in a vector called a? Command and Results: What MATLAB command will pull out every other entry of the vector, x, starting at entry 4 and ending at entry 12 and store these entries in a vector called b? Command and Results: b) What MATLAB command will pull out the7 in matrix, M, and store it in a scalar variable called c? Command and Results: c) What MATLAB command will pull out row 3 of the matrix, M, and store these values in a row vector called d? Command and Results: d) What MATLAB command will pull out column 4 of the matrix, M, and store these values in a column vector called e? Command and Results: e)Explanation / Answer
Answer:
a)
>>a= x(7:12) #Command to pull out 7 to 12 elements
Output:
a =
0 2 5 5 -1 5
b)
>> b=x(4:12) #Command to pull out 4 to 12 elements
Output:
b =
5 3 -2 0 2 5 5 -1 5
c)
>> c=x(7) #Command to pull out 7 th element
Output:
c = 0
d)
#Command to pull 3 rd row and all the columns corresponding to the selected row-- M(i,j) ,where( i=3 and j=: to indicate all the columns)
>> d=M(3,:)
Output:
d =
-2 5 -3 -2 5
e)
#Command to pull all the rows(i=:) and 4th column -- M(i,j) ,where i=: and j=4
>> e=M(:,4)
e =
2
3
-2
2
2
-4
f)
#Command to pull rows from 2nd to 5th and columns from 2 to 4th corresponding to selected row ..
>> f=M(2:5,2:4)
Output:
f =
-2 7 3
5 -3 -2
-5 0 2
-1 -1 2