Matrix and Array Operations
Matrix and Array Operations
MATRIX OPERATIONS
OBJECTIVES
Reshaping Matrices
Matrices can be reshaped into a vector or any other
appropriately sized matrix
As a vector Stacked to single coloumn vector. E.g. b=A(:)
As a differently sized matrix If a matrix A is an mXn matrix
then it can be reshaped to pXq , as long as mXn = pXq with the
command reshape(A,p,q)
Utility Matrices
eye
zeros
ones
rand
randn
diag
diag(A,1)
rot90
fliplr
flipud
tril
triu
Reshape
Disp()
Length()
Size()
Matrix & Array Operations
Arithmetic Operations
MATLAB allows operators like +(addition), -(Substraction),
*(Multiplication), /(Division) ^ (Exponentiation)
A+B or A-B valid if A&B are of same size.
Relational Operations
< <= > >= == ~=
Ex.
If x=[1 5 3 7] and y=[0 2 8 7]
Then k=x<y results in k=[0 0 1 0]
k=x<=y results in k=[0 0 1 1]
K= x>y [1 1 0 0]
K= x>=y [1 1 0 1]
K= x == y [0 0 0 1]
K= x~=y [1 1 1 0]
These are normally used in conditional statements as if-then-else
Matrix & Array Operations
Logical Operations
& | ~ xor
Ex. Let x=[0 5 3 7] and y=[0 2 8 7]
Then m=(x>y)&(x>4) results m=[0 1 0 0]
N=x|y [