Page 23 - Basics of MATLAB and Beyond
P. 23
>> q = [spiral(3) [10;20;30]]
q =
7 8 9 10
6 1 2 20
5 4 3 30
>> q(end,end)
ans =
30
>> q(2,end-1:end)
ans =
2 20
>> q(end-2:end,end-1:end)
ans =
9 10
2 20
3 30
>> q(end-1,:)
ans =
6 1 2 20
3.6 Deleting Rows or Columns
To get rid of a row or column set it equal to the empty matrix [].
>>a=[123;4 56;789]
a =
1 2 3
4 5 6
7 8 9
>> a(:,2) = []
a =
1 3
4 6
7 9
3.7 Matrix Arithmetic
Matrices can be added and subtracted (they must be the same size).
>> b = 10*a
b =
10 30
40 60
70 90
c 2000 by CRC Press LLC