matlab the language of technical computing. outline introduction c++ vs. matlab functions graphing...

25
Matlab The language of technical computing

Post on 20-Dec-2015

239 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

MatlabThe language of technical

computing

Page 2: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Outline•Introduction

•C++ vs. Matlab

•Functions

•Graphing

•Matrix

•Image processing toolbox

•Neural network toolbox

•Menu

Page 3: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Introduction

• Things we like about Matlab

• Things we don’t like about Matlab

Page 4: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Help

Help command

Help svd

Page 5: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

C++ vs. Matlab

int j;

.

for (j=1;j<23;j=j+2)

{

A[4][j]=3*j;

}

for i = 1:2:N

for J = 1:N

A(I,J) =(I+J-1);

end

end

Page 6: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

C++ vs. Matlab (cont.)

int j;

while (j<28)

{

…….;

}

while N> 0,

E = E + F;

F = A*F/N;

N = N + 1;

end

Page 7: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

C++ vs. Matlab (cont.)

If (i==j)

{ A[i][j]=2;

}

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

Page 8: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

C++ vs. Matlab (cont.)

• Index to an array can be zero.

• double, float , int…

• “;” is very important

• Index into matrix can’t be negative or zero.

• Don’t need to worry about the data type

• “;” not so important

Page 9: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Functions

double* stat(double *x)

{

…….;

return stdev;

}

function [mean,stdev] = stat(x)

n = length(x);

mean = avg(x,n);

stdev =…

function mean = avg(x,n)

mean = sum(x)/n;

Page 10: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Functions(cont.)

function Matrix2VectorAv=A(1,:);for i=2:x Av=[Av A(i,:)];endAv=Av';

void Matrix2Vector( )

{

……;

……;

}

Page 11: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Functions(cont.)

A function declaration cannot appear within a script M-file

void AddF(int i);

int main()

{ ……addF(i);

}

void AddF(int i)

{

i=i+1;

}

File name testFunR.m function testFun

i=2;

AddF(i);

i

function AddF(i)

i=i+1;

Page 12: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Graphing

In file PlotTest.m

t = 0:.3:10;

y = sin(t);

plot(t,y,’r’) ;

To make a graph of y = sin(t) on the interval t = 0 to t = 10

Page 13: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Graphing(cont.)

graphing the fuction z(x,y) = x exp( - x^2 - y^2)

In file MeshTest.m

[x,y] = meshgrid (-2:.2:2, -2:.2:2);

z = x .* exp(-x.^2 - y.^2);

mesh(z)

Page 14: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Graphing(cont.)

Multiple windows in one figure

SubplotTest.m

t = 0:.3:10;

y = sin(t);

z= cos(t);

subplot(2,1,1);

plot(t,y) ;

subplot(2,1,2);

plot(t,z);

Page 15: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Graphing(cont.)

Multiple windows in one figure

SubplotTest.m

t = 0:.3:10;

y = sin(t);

z= cos(t);

subplot(1,2,1);

plot(t,y) ;

subplot(1,2,2);

plot(t,z);

Page 16: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Matrix

>> A=[1 2 3;3 2 1]

A =

1 2 3

3 2 1

>>b=A(1,:)

b =

1 2 3

>> B=A'

B =

1 3

2 2

3 1

Page 17: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Matrix Manipulation

•Singular value decomposition---[U,S,V]=svd(A)

•Eigenvalues and eigenvectors---[V,D] = eig(A)

• Orthogonal-triangular decomposition- [Q,R]=qr(A)

•LU factorization --[L,U] = lu(A)

•Matrix rank -- a=rank(A)

•Condition number -- a=cond(A)

Page 18: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Image Processing Toolbox

•Read an image ---- I=imread(filename)

•Display an image ---- imshow(I)

•Write an image ---- imwrite(I, filename,FMT)

Page 19: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Image Processing Toolbox(cont.)

ImageRWD.mfunction ImageTest

Itif=imread('image1.tif');

imwrite(Itif,'image1.bmp','bmp');

Ibmp=imread('image1.bmp');

subplot(1,2,1);

imshow(Itif);

subplot(1,2,2);

imshow(Ibmp);

Page 20: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Image Processing Toolbox(cont.)

EdgeTest.m

function EdgeTest

Itif=imread('image1.tif');

B=edge(Itif,'canny');

subplot (1,2,1);

imshow(Itif);

subplot(1,2,2);

imshow(B);

Page 21: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Image 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…

Page 22: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Neural Network

•Feed-forward backpropagatoin

•Hopfield Networks

•Self-organizing maps

•Radial Basis networks

•………………

Page 23: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Neural Networks(cont.)

•Create feed-forward NN•Net=newff([-1 2;0 5],[31],{‘tansig’,’purelin’},’traingd’);

•Training •[net,tr]=train(net,p,t)•net.trainParam.????; “show”, “lr”, “epochs”, “goal”

•Simulation

•A=sim(net,q);

•Neural Model – tansig, logsig, purelin.•Training method –traingd, traingdm.

Page 24: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Menu

function MenuDemo

cell_list = {};

fig_number = 1;

title_figure = 'Menu Demo';

cell_list{1,1} = {'Plot','PlotTest;'};

cell_list{1,2} = {'Mesh','MeshTest;'};

cell_list{1,3} = {'Image','ImageRWD;'};

cell_list{1,4} = {'Image Edge','EdgeTest;'};

cell_list{2,1} = {'????','PlotTest;'};

cell_list{2,2} = {'????','PlotTest;'};

cell_list{2,3} = {'????','PlotTest;'};

cell_list{2,4} = {'Exit',['disp(''Bye. To run again, type "menu".'');

close(' num2str(fig_number) ');']};

show_window(cell_list,fig_number,title_figure,120,20,3);

Page 25: Matlab The language of technical computing. Outline Introduction C++ vs. Matlab Functions Graphing Matrix Image processing toolbox Neural network toolbox

Menu (cont.)

•cell_list{1,1} = {‘name',‘function;'};

•show_window(cell_list,fig_number,title_figure,x,y,z);