Title: Matlab
1Matlab
- The language of technical computing
2Outline
3Introduction
- Things we like about Matlab
- Things we dont like about Matlab
4Help
Help command
Help svd
5C vs. Matlab
int j . for (j1jlt23jj2)
A4j3j
for i 12N for J 1N
A(I,J) (IJ-1) end end
6C vs. Matlab (cont.)
int j while (jlt28) .
while Ngt 0, E E F
F AF/N N N 1 end
7C vs. Matlab (cont.)
If (ij) Aij2 else if
(abs(i-j)!1) .
if i j A(i,j) 2 elseif abs(i-j)
1 A(i,j) -1 else A(i,j)
0 end
8C vs. Matlab (cont.)
- Index to an array can be zero.
- double, float , int
- is very important
- Index into matrix cant be negative or zero.
- Dont need to worry about the data type
- not so important
9Functions
function mean,stdev stat(x) n length(x)
mean avg(x,n) stdev
function mean avg(x,n) mean sum(x)/n
double stat(double x) . return stdev
10Functions(cont.)
void Matrix2Vector( )
- function Matrix2Vector
- AvA(1,)
- for i2x
- AvAv A(i,)
- end
- AvAv'
11Functions(cont.)
void AddF(int i) int main() addF(i) void
AddF(int i) ii1
File name testFunR.m
function testFun i2
AddF(i) i
function AddF(i)
ii1
A function declaration cannot appear within a
script M-file
12Graphing
To make a graph of y sin(t) on the interval t
0 to t 10
In file PlotTest.m t 0.310 y sin(t)
plot(t,y,r)
13Graphing(cont.)
graphing the fuction z(x,y) x exp( - x2 - y2)
In file MeshTest.m x,y meshgrid (-2.22,
-2.22) z x . exp(-x.2 - y.2) mesh(z)
14Graphing(cont.)
Multiple windows in one figure
SubplotTest.m t 0.310 y sin(t) z
cos(t) subplot(2,1,1) plot(t,y)
subplot(2,1,2) plot(t,z)
15Graphing(cont.)
Multiple windows in one figure
SubplotTest.m t 0.310 y sin(t) z
cos(t) subplot(1,2,1) plot(t,y)
subplot(1,2,2) plot(t,z)
16Matrix
gtgt A1 2 33 2 1 A 1 2 3 3
2 1
gtgtbA(1,) b 1 2 3
gtgt BA' B 1 3 2 2 3 1
17Matrix Manipulation
- Singular value decomposition---U,S,Vsvd(A)
- Eigenvalues and eigenvectors---V,D eig(A)
- Orthogonal-triangular decomposition- Q,Rqr(A)
- LU factorization --L,U
lu(A)
- Condition number -- acond(A)
18Image Processing Toolbox
- Read an image ---- Iimread(filename)
- Display an image ---- imshow(I)
- Write an image ---- imwrite(I,
filename,FMT)
19Image Processing Toolbox(cont.)
ImageRWD.m function ImageTest Itifimread('image1.
tif') imwrite(Itif,'image1.bmp','bmp') Ibmpimre
ad('image1.bmp') subplot(1,2,1) imshow(Itif) su
bplot(1,2,2) imshow(Ibmp)
20Image Processing Toolbox(cont.)
EdgeTest.m function EdgeTest Itifimread('image1.t
if') Bedge(Itif,'canny') subplot
(1,2,1) imshow(Itif) subplot(1,2,2) imshow(B)
21Image Processing Toolbox(cont.)
- Pixel values and statistics --corr2,imhist
- Image enhancement histeq, medfilt2
- Linear filter -- conv2, filter2
- Image transform -- dct2, fft
- Binary image Op. --- dilate, erode
22Neural Network
- Feed-forward backpropagatoin
23Neural Networks(cont.)
- Netnewff(-1 20 5,31,tansig,purelin,tr
aingd)
- Neural Model tansig, logsig, purelin.
- Training method traingd, traingdm.
- net.trainParam.???? show, lr, epochs,
goal
24Menu
function MenuDemo cell_list fig_number
1 title_figure 'Menu Demo' cell_list1,1
'Plot','PlotTest' cell_list1,2
'Mesh','MeshTest' cell_list1,3
'Image','ImageRWD' cell_list1,4 'Image
Edge','EdgeTest' cell_list2,1
'????','PlotTest' cell_list2,2
'????','PlotTest' cell_list2,3
'????','PlotTest' cell_list2,4
'Exit','disp(''Bye. To run again, type
"menu".'') close(' num2str(fig_number)
')' show_window(cell_list,fig_number,title_fi
gure,120,20,3)
25Menu (cont.)
- cell_list1,1 name',function'
- show_window(cell_list,fig_number,title_figure,x,y,
z)