col4=mymatrix( : , 4): extract column 4 from mymatrix
col2thru4=mymatrix( : , 2:4 ): extract columns 2,3 and 4 from mymatrix
r2c3=mymatrix( 2 , 3 ): extract element (2,3) from mymatrix
If matrices conform, then the standard operations of linear
algebra can be carried out. Thus a matrix of size
can be
multiplied by a matrix of size
to give a result of size
. In particular:
>> a=[1 2 3]
a =
1 2 3
>> b=[4;5;6]
b =
4
5
6
>> b*a
ans =
4 8 12
5 10 15
6 12 18
and similarly the scalar or inner product of a and b is formed from:
>> a*b
ans =
32
>>
Furthermore matrices can be added and subtracted so long as they
conform. It is often useful to be able to take the transpose of a matrix
(i.e. rows become columns and vice-versa). We have
a': gives the transpose of the vector or matrix a
>> a=[1 2 3; 4 5 6]
a =
1 2 3
4 5 6
>> a'
ans =
1 4
2 5
3 6
>>
but note that for complex-valued elements, this operator forms the complex
conjugate of each element (the Hermitian conjugate, which is often more
useful in practical applications than the straight transpose).
Finally, here are some special operations on arrays:
max(array): returns a row vector of column maxima (similarly for min)
max(max(array)):returns the array maximum.
[m,n]=size(array): returns row and column dimensions in m and n respectively.
len=length(array): returns maximum of row and column dimensions in len.