some tips for MATLAB

basics

description code
not equal ~=
and &&
or II
print disp();
matrix [row element; row element…]
speical matrix zeros/ones/rand (row, column)
eye(size) for indentity matrix
sequence start:interval:end
help help xxx
size of matrix size(matrix,)
\
: 1—no of row
2—no of column
length length()
current directory pwd
input file load xxxx.xxx
output file save xxxx.xxx b(variables);
clear all variables clear
comment %

Matrix manipulation

description code
select element of matrix A([1 3], : )— means exact all elements
from 1st & 3rd rows
add column A = [A, [1; 2; 3]]
matrix to vector A(:)
concatenating matrix c = [A B] or c = [A; B]
multiplication *
element operation .+ .- .* etc.
maximum max()., note that max(matrix) gives max column
exact element with condition eg. find(A < 3)
max element for rows/cols max(A, [ ], 1 or 2)
reflect matrix flipud()
inverse matrix pinv()
transpose transpose of a: a’

Plots

description code
multiple lines on a plot hold on;
subplot: divide plot into b x c grid,
access dth element
subplot(b, c, d)

control statements

while:

1
2
3
while condition  
do something;
end

for:

1
2
3
for i= some series  
do something;
end

if else:

1
2
3
4
5
6
7
if condition
do something;
elseif condition
do something;
else
do something;
end

function:

1
2
3
4
function [a, b] = undermat(x, y)
a = x^2;
b = a + y;
end