Practice Exercises Arrays: Instructions
Practice Exercises Arrays: Instructions
Instructions:
Download the Array.mat file and save it in your current MATLAB directory. At the command
prompt, type >> load Array. Look in your workspace window. You should see a 1-d array
called vector (1x12), and a 2-d array called matrix (10x5).
All of these problems refer to the arrays vector and matrix downloaded from the Array.mat file.
Don’t change the values in vector or matrix unless prompted. If you do inadvertently change
them, just re-run the command >> load Array to recover the original arrays.
Execute the following command first so you know what vector looks like.
>> vector
a) Give a single MATLAB command that will pull out entries 5, 6, 7, 8, 9 out of the 1-d array,
vector and put them in another vector called vectorA. Show both your command and the
results here:
b) Give a single MATLAB command that will pull out entries 3, 9, and 11 out of the 1-d array,
vector and put them in another vector called vectorB. Show both your command and the
results here:
c) Give a single MATLAB command that will overwrite the 3rd entry in vectorB with a value of
12. Show both your command and the results here:
Execute the following command first so you know what matrix looks like.
>> matrix
a) Give a single MATLAB command that will pull out rows 5, 6, and 7 out of the 2-d array,
matrix and put them in another matrix called matrixA. Show both your command and the
results here:
b) Give a single MATLAB command that will pull out columns 2, 3, and 4 out of the 2-d
array, matrix and put them in another matrix called matrixB. Show both your command
and the results here:
c) Give a single MATLAB command that will replace the values in rows 1 & 2 and columns 2
& 3 of matrixB with the following values:
Problem 3: Arrays, Relational Operators, and Useful functions (sum and find)
This problem refers to the array vector loaded from the Array.mat file. Again, don’t overwrite
the values in the array vector. If you do, re-load Array.mat. For each of these commands,
show the result and explain the result in words.