If you can't read please download the document
Upload
pinglun-liao
View
1.486
Download
1
Embed Size (px)
Citation preview
Matlab:
Syllabus
Matlab Overview
Vectors & Matrices
M Files
2d Graphics
(optional)
MATLAB
MATLAB
current folder
workspace
MATLAB editor
MATLAB command window MATLAB
versionver
bench
doc, help
who
clear
^c
demo
MATLAB quitexit
3 + 4
3 ^ 3
...etc
X = 3 + 4 ^ 4 4
MATLAB X = 3 + 4 ^ 4 4;
31 MATLAB
MATLAB Variable Declaration double 8bytes
Comments%y = (5*2+3.5)/5; % y
z = y^2 % z
A i j A(i, j) i j SubscriptIndex
MATLAB A(i, j) A(i+(j-1)*m) mA
MATLAB VectorsMatrixs = [1 2 3 4]; t = 2*s+1;
t(3) = 2 % t 2
t(6) = 10 % t 10
t(4) = [] % t []
t(2:4) 1
mn m n ;A = [1 2 3 4; 5 6 7 8; 9 10 11 12];
zeros(m, n) % mn 0
ones(m, n) % mn 1
rand(m, n) % [0, 1] mn
Example: matrice_demo.m
if
switch
while
for
if
if {} {};end
if {} {};elseif{} {};else {4};end
Example: if_demo.m
switch
switch switch_expr case case_expr, statement, ..., statement case {case_expr1, case_expr2, case_expr3,...} statement, ..., statement ... otherwise, statement, ..., statement end
Example: switch_demo.m
Loops
while expression {statements};end
for var = expression {statements};EndExample: while_demo.m, for_demo.m
Matlab(M files)
M files( *.m)
Scripts ()
Functions ()
Edit
Open filename.m
Edit filename.m
Execute
Filename (without .m extension)
Example
TheScripts.m
FunFunc.mFunFunc 1
FunFunc(1)
FunFunc X
Scripts
MATLAB
MATLAB\
%CTRL + r CTRL + t
MATLAB Base Workspace
Scripts
Input/Output ArgumentsTheScripts2 arg1 arg2 ==> fail
Functions
M
MATLAB
Modularized
Subfunctions
M
Primary Function
Subfunctions
function [out1,out2, ..., outN] = myfun(in1,in2,in3, ..., inN)
Example: demo.m
Example
FunFunc.m
Which is false?
FunFunc(4)
[a b] = FunFunc(4)
[a b] = FunFunc(magic(3))
[a b] = FunFunc([1 2 3])
mean
median
mode
max
min
Example: sta_demo.m
var
std
range
corrcoef
Probability Distributions
Probability density functionsY = exppdf(X, mu)
Y = normpdf(X, mu, sigma)
Cumulative density functionsY = expcdf(X, mu)
Y = normcdf(X, mu, sigma)
Example: pdis_demo.m
(Random Number Generators)
Probability density functions (pdf)
rand
randn
Poisson poissrnd
(Normal (Gaussian)) normrnd
(Exponential) exprnd
random
randtool
Example: rnd_demo.m
plot
x y plotxy01.m
x = linspace(0, 2*pi);% 0 2*pi 100 y = sin(x);% x plot(x, y);%
Plot-2
x y plot
plotxy02.m
x = linspace(0, 2*pi);% 0 2*pi 100 plot(x, sin(x), x, cos(x), x, sin(x)+cos(x));%
Plot-3
Markerplotxy03.m
x = linspace(0, 2*pi);% 0 2*pi 100 plot(x, sin(x), 'o', x, cos(x), 'x', x, sin(x)+cos(x), '*');
Plot-4
y y (Column Vector)
plot04.m
y = peaks;% 4949 plot(y);% y
Plot-5
x y
plot(x, y) y x plotxy05.m
x = peaks; y = x';% x x' plot(x, y);% y x %
MATLAB
(Ex : maxmin mean)
hist
(Histogram)
PDF, probability density function
hist
10000 randn 25 plotxy20.m
Result
% 10000 x = randn(10000, 1);% 25hist(x, 25);
normDemo.m
normExample.m
Debugger
MATLAB (Debugger)
Workspace
Function Call Stack
M Step-by-step Execution
(1/2)
MATLAB
keyboard k >>k keyboard MATLAB return Enter
Example: debugger.m
(2/2)
fprintf
%Scripts M MATLAB
MATLAB
edit open
>> edit debugger MATLAB
MATLAB
dbstop/dbclear
dbclear all
dbstep
dbstep in
dbstep out
dbcont
dbquit
dbtype
(1)
( )
(2)
>> debugger ( )
stack
Evaluate Selection
dbstep
dbstep
MATLAB
/
MATLAB
dbstop/dbclear
dbclear all
dbstep
dbstep in
dbstep out
dbcont
dbquit
dbtype
Who am I
2006~20102007/9~2011/10 2011/12~2014/10 ()Blog:http://kusogameprogramming.blogspot.tw/FaceBook:https://www.facebook.com/LiaoPingLunGoogle+:https://plus.google.com/+PingLunLiaoYoutube:https://www.youtube.com/channel/UClnsiixSemOSeq2Nu-82RFQEmail: pinglunliao at gmail dot comLINE ID: Holan.Liao