Matlab_02b
Matrix manipulation
Matlab stores as many values as you wish inside one variable name in either a row, or a column, or a multi-dimensional structure.
First example is a row of values:
a = [1 2 3 4]; % the values are separated by spaces
The second example is a column of values:
source_data = [3.22; 6.77; 8.45; 0.11; 7.02]; % separated by semicolons
And the third example contains rows and columns:
readings = [2 3 4; 5 3 2; 3 4 5; 5 3 1];
The example above is a 4-by-3 matrix, 4 rows and 3 columns.
How many rows and how many columns are there in the variable my_readings
? If there is any doubt type:
size(readings)
This will give you the size of matrix - rows first and then columns. To see the average of each column type:
mean(readings,1)
And to get the average of the rows type:
mean(readings,2)
Try out the following lines. What do they do?
max(readings);
max(readings(:));
imagesc(readings);
plot(readings);
plot(readings');