INTRODUCTION TO MATLAB PROGRAMING
SIMPLE CALCULATION & PRECEDENCE Operators ª + ¨ ¼ * ®µ¦ / ¥Îµ¨³ ^
1st 2nd 3rd 4th
Precedence ªÁ¨È Á¦·É¤µªÁ¨ÈÄ»n° ¥Îµ¨´ µoµ¥Å
ªµ ¼Â¨³®µ¦ µoµ¥Å
ªµ ªÂ¨³¨ µoµ¥Å
ªµ
Example 1 3^2-5-6/3*2 3^2-5-6/3*2 9-5-6/3*2 9-5-2*2 9-5-4 4-4 0 3^2-5-6/(3*2) 3^2-5-6/(3*2) 3^2-5-6/6 9-5-6/6 9-5-1 4-1 3
VARIABLES
• µ¦´ÊºÉ°´ªÂ¦o°¦³°oª¥´ª°´¬¦´ªÁ¨È, ´ª Ä®n, ´ªÁ¨
®¦º° “_” Ã¥o°
¹Êooª¥´ª°´¬¦Ánµ´Ê ¨³ º°ªnµ°´¬¦´ªÁ¨È¨³´ªÄ®nnµ´ • ®µºÉ°´ªÂ¦¥µª¤µªnµ 31 ´ª°´¬¦ ´ª°´¬¦´ª¸É 32 Á}oų¼´·Ê
VARIABLES
• ε¸É®oµ¤Îµ¤µ´ÊÁ}ºÉ°´ªÂ¦ º° for, end, if, while, function, return, elseif, case, otherwise, switch, continue, else, try, catch, global, persistent, break • Ťnª¦ÎµºÉ°¢{r´É ¨³ ´ªÂ¦¡·Á«¬
° MATLAB ¤µ´ÊÁ}ºÉ°´ªÂ¦ Ã¥´ªÂ¦¡·Á«¬
° MATLAB ¤¸ ´¸Ê ans, beep, pi, eps, inf, NaN, nan, i, j, nargin, nargout, realmin, realmax, bitmax, varargin, varargout
SPECIAL VARIABLES ans pi
ε°¨nµ» nµ¸É S = 3.14159265358979
i,j
®nª¥·£µ¡
inf
nµ¸ÉÁ·µµ¦®µ¦oª¥ 0 (Infinity)
NaN,nan
µ¦Îµª¸®É µnµÅ¤nÅo (Not a Number) Án 0/0 ®¦º° inf-inf
varargin
cell
° input argument
varargout
cell
° output argument
nargin
뵻 input argument
nargout
뵻 output argument
eps
¦´¥´®nµ¸Éo°¥¸É»¦´®ªnµ 2 εª = 2.2204e-016
realmin
³ªÁ¨
floating point ª¸É o°¥¸É» = 2.2251e-308
realmax
³ªÁ¨
floating point ª¸¤É µ¸É» = 1.7977e+308
bitmax
³ªÁ¨
εªÁȤ floating point ¸¤É µ¸É» = 9.007199254740991e+015
clock
Äo° e-Áº°-ª³-³ÉªÃ¤-µ¸-ª·µ¸
date
ª³¸É Ħ¼Â ª³-Áº°-e
VARIABLES Example 2 tile_length = 1 tile_width = 0.5 tile_area = tile_length*tile_width floorarea = 1 FLOORAREA = 2 FloorArea = 3 TileCost_1 = (15*(floorarea/tile_area))+50 TileCost_2 = (15*(FLOORAREA/tile_area))+50 TileCost_3 = (15*(FloorArea/tile_area))+50
VARIABLES Example 3 realmax eps clock date
Example 4 pi r = 1.2
pi*(r^2)
pi*(r^2)
clear pi
pi = 3
pi
pi
pi*(r^2)
VARIABLES Example 5
Example 6
2*2+5 ans
z1 = -1+i
z1*i
-2^2;
z2 = -1+j
clear i
ans
z1*i
i
i=2
z1*i
2*ans; ans
ARRAYS & MATRICES
µ¦¦oµ array ®¦º° Matrix Ä MATLAB µ¤µ¦Îµ®Åooª¥ [ ] nµ¦³®ªnµ®¨´³¼´É oª¥ space ®¦º° , µ¦
¹ÊªĮ¤nµ¤µ¦Îµ Åooª¥µ¦ Enter ®¦º° ´Éoª¥ ;
Example 7.1 a = [1,2,3] a = [1 2 3] b = [-1;0;1] b = [-1 0 1] C = [1,0,-1;0,1,0;0,0,2] C = [1 0 -1;0 1 0;0 0 2] C = [1 0 -1 010 0 0 2]
ARRAYS & MATRICES
Array ÂŨnª´ Á¨
µ¤µ¦ ε®Åo´ ¸Ê Start:Step:Stop Start º° nµ´ªÁ¨
Á¦·É¤o Step º° ¦³¥³®nµ¦³®ªnµ ®¨´´Å´®¨´{»´ Stop º° µ¦Îµ®Ä®onµ »oµ¥
°µ¦Å¨nª´ Á¨
Ťn Á¨¥nµ Stop
Example 7.2 d = 1:1:3 d = 1:3 e = 1:2:6 f = 1:2:5 g = 3:-1:1 h = 3:1
Start:Stop Start:1:Stop
ARRAYS & MATRICES
µ¦°oµÎµÂ®nÄ Array 1 ¤·· µ¤µ¦ÎµÅoÃ¥
A(index) A º° ºÉ° Array ¨³ index º° ε®n¸Éo°µ¦ index µ¤µ¦Á} Array ÅoÁ¤º°o°µ¦°oµÎµÂ®n
¸É°o µ¦¤µªnµ 1 ε®n µ¦°oµÎµÂ®nÄ Array n ¤·· µ¤µ¦ÎµÅoÃ¥ A(index_1, index_2,…, index_n)
ARRAYS & MATRICES Example 7.3 a(1) b(2) a(end) b(end) a(end-1) a(1:2) b(3:-1:2) a([1 3]) a([1 3 2]) a([1 3 2 3]) b(2:end) b(1:end) b(:)
Example 7.4 C(3,2) C(end,2) C(end,end) C(1:2,1) C(1:2,2:3) C([1 3],[1 3]) C(1,2:end) C(1,1:end) C(1,:) C(:,1) C([1 3],:) C(:,[1 3]) C(:,:)
ARRAYS & MATRICES Example 7.5 a(1,3) b(2,1) C(:) C(5) C(end) C(1:8) C(1:end)
Example 7.6 a' [a;e] [b a'] L = [C b;a 7] L(1,1) = 5 L(2:3,2:3) = [-1 -2;-4 -6] L(end,:) = 2:2:8 L([5 10 end]) = 10 save Example_07.mat
CHARACTER ARRAYS (STRINGS)
µ¦¦oµ´ªÂ¦¦³Á£ ´ª°´¬¦µ¤µ¦¦³»Åo Ã¥Äo ' '
Example 8 s1 = 'DSP' s2 = ['D' 'SP'] s3 = '371' [s1 s3] ['s1' s3] s4 = 100 s5 = '100' s4+1 s5+1 s1(1) s1([1 3])
OPERATORS AND SPECIAL CHARACTERS = + * .* ^ .^ / ./ \ .\ ’ .’
µ¦Îµ®nµ³ªÂ¦ ª ¨ ¼ÂÁ¤¦·r ¼Â°µÁ¦¥r ¥Îµ¨³ÂÁ¤¦·r ¥Îµ¨³Â°µÁ¦¥r ®µ¦µ
ªµÂÁ¤¦·r ®µ¦µ
ªµÂ°µÁ¦¥r ®µ¦µoµ¥ÂÁ¤¦·r ®µ¦µoµ¥Â°µÁ¦¥r transpose & conjugate transpose
== ~= > >= < <= & | ~ . .. …
Ánµ³
¨ε³Äµ¦Îµª
()
ŤnÁnµ³ ¤µªnµ
°oµÎµÂ®nÄÁ¤¦·r
¤µªnµ®¦º°Ánµ³ o°¥ªnµ o°¥ªnµ®¦º°Ánµ³ ¨´ ®¦º° ·Á
°·¡»Ä¢{r³É
[] {} ‘ ’ , ;
: Á¦¸¥nµ
° field Ä structure % parent directory Äo³ ε³É cd @ ε³É n°Ä¦¦³³Å ! »«·¥¤
¦oµÁ¤¦·r ¦oµ®¦º°°oµÎµÂ®nÄ cell ε®³ªÂ¦¦´Á£ String ÄoÁ}³ªÂn®¦º°³ªÂn®¨³ ÄoÁ}³ªÂnª Ťn¨
°¦¦³¸Ê Äo¦oµ¨Îµ³Á¨
·  comment ¦oµ function handle Á¦¸¥Äoε³É
° OS
OPERATORS AND SPECIAL CHARACTERS
Operator ¸¤É ¸ . °¥¼n
oµ®oµ Án .* ./ .\ .^ ³Á} Array Operator ¹Éµ¦Îµª ³Îµ´¤µ·ÎµÂ®n n°ÎµÂ®n Operator ¸ÅÉ ¤n¤¸ . °¥¼n
oµ®oµÁn * / \ ^ ³Á} Matrix Operator ¹Éµ¦ εª°·µ¤®¨´µ¦
° Matrix
Example 9 M1 = [1 2;3 4] M2 = [-2 1;-1 2] M1+M2 M1-1 2*M1 M1.*M2 M1*M2 M1./M2 M1/M2 M1.\M2 M1\M2 M1.^2 M1^2
M 1M 21 M 11M 2
GENERAL PURPOSE COMMAND help
ª·¸Äoε³É ®¦º°¢{r³É
lookfor
o®µº°É ε³É ®¦º°¢{r³É
demo
Á¦¸¥Äo Demo
clear
¨nµ³ªÂ¦Ä Workspace
save
³¹nµ³ªÂ¦Ä Workspace
load
¹nµµÅ¢¨r .mat ¤µÄªoÄ Workspace ¨ Command window
clc format
宦¼Âµ¦Â¨
°³ªÁ¨
warning ®¦º°Å¤nÂεÁº° beep
nÁ¸¥ Beep
quit
°°µÃ¦Â¦¤ MATLAB
NUMBER DISPLAY FORMAT format short (default)
Á¨
5 ®¨³
3.1416
format long
Á¨
15 ®¨³
3.14159265358979
format short e
Á¨
5 ®¨³¤¸Á¨
¥Îµ¨³µ 10
3.1416e+000
format long e
Á¨
15 ®¨³¤¸Á¨
¥Îµ¨³µ 10
3.14159265358979e +000
format bank
«·¥¤ 2 ®¨³
3.14
format +
Á¦ºÉ°®¤µ¥ (+,-)
+
format hex
Á¨
µ 16
400921fb54442d18
format rat
Á«¬nª (Ã¥¦´¤µ)
355/113
FUNCTIONS
µ¦Á¦¸¥Äo Function Ä MATLAB µ¤µ¦ÎµÅoÃ¥
F(input_1, input_2,…,input_n) F º° ºÉ° Function ¨³ input º° nµ°·¡»
° Function (εª
°´ªÂ¦°·¡»³¼Îµ®Ã¥ Function) Example 10.1 sqrt(2)
max([1 5 6 2])
gcd(10,15)
inv([1 2;3 4])
FUNCTIONS
µ¦Îµ®´ªÂ¦¤µ¦´nµ Output
° Function εÅoÃ¥ out = F(input_1, input_2,…,input_n) [out_1,out_2,…,out_n] = F(input_1, input_2,…,input_n) [out_1 out_2 … out_n] = F(input_1, input_2,…,input_n) Example 10.2 out_a = sqrt(2)
out_c = inv([1 2;3 4])
out_b = mean([1 5 6 2])
[out_1,out_2] = size(out_c )
M-FILES
Á
¸¥Ä榤¦³Á£ Editor ¨oª´ÉÁÈÁ}Å¢¨r Á¡ºÉ°Îµ¤µ´ÉεµÅoÄ£µ¥®¨´Ä MATLAB MATLAB ¤¸
o°´´ªnµ³o°¦³»µ¤»¨
°Å¢¨r Á} .m ¨³³o°ÁÈŪoÄÅÁ¦°¦¸
° MATLAB µ¤µ¦Á¦¸¥Ã¦Â¦¤Å¢¨rÁ¸É ÈÁ}· .m ´ÊÄ
®oµnµ¦´Îµ´É
° MATLAB oª¥µ¦j°ºÉ°Å¢¨r´Ê¨Å ®¦º°µ¤µ¦Á¦¸¥ÄoÅ¢¨r .m µÅ¢¨r .m °ºÉÈÅo
M-FILES
o°¦³ª´Èº° ³o°´¹Å¢¨r¸ÊŪoÄÅÁ¦°¦¸¸É MATLAB µ¤µ¦ ¤°Á®È ®¦º°Á¦¸¥ªnµ MATLAB Path ¹Éµ¤µ¦¦ª¼ÅoµÎµ´É path ®¦º°°µ³ÁÈŪoÄ ÅÁ¦°¦¸{»´
° Window ÈÅo ¹É³Â °°¤µÁ¤ºÉ°Äoε´É pwd ®¦º° Tab Current Directory Ħ¸¸Éo°µ¦ÁÈŪoÄÅÁ¦°¦¸°ºÉ Ç Èµ¤µ¦Á·¤ºÉ°Á¡·É¤¨Å Ä MATLAB Path Ã¥Äoε´É addpath (¼ help addpath)
M-FILES
Script File Ã¥ Script File Á}»Îµ´É
Function File Function File Á}µ¦¦oµ¢{r´Ä®¤n ¹É
Ã¥´ÉªÅ³¤¸µ¦nnµnµ´ªÂ¦Á
oµ ¨³ ´ªÂ¦°°
SCRIPT FILE
Á¦µµ¤µ¦ÁȻε´É¸Éj°Ä®o´ MATLAB ŪoÄÅ¢¨r¸É¤¸µ¤»¨ .m ¨³´É Ä®o MATLAB Å Á¦¸¥»Îµ´ÉµÅ¢¨r¸ÊÁ¤º°´Á¦µj°Îµ´É Á
oµÅ¸¨³Îµ´ÉÅo µ¦Á¦¸¥ÄoÅ¢¨r¸É ´ ¹ÅªoÁ}»Îµ´É¸É Command Window µ¤µ¦ÎµÅoÃ¥ ¡·¤¡rºÉ° Å¢¨råŤno°¤¸ .m ¨oª Enter
SCRIPT FILE Example 11 Editor Comment
% Find x from Ax = b clear A b x A = [1 2 3;1 0 -1;-2 3 -1]; b = [1;0;-5]; x = A\b Save as ex11.m Command Window ex11
FUNCTION FILES
Function Á} m-file ¸É¤¸ µ¦ ‘nnµ’ Å¥´ Function ¨³ ‘¦´nµ’ µ Function Function ¤¸µ¦¦´nnµ´ªÂ¦Åo script ¦´n´ª nµ´ªÂ¦Å¤nÅo Function Äo´ªÂ¦
°´ªÁ°Å¤n¦ª¤´ Command Window ®¦º° Function °ºÉ Ç (´ªÂ¦³¼ ¦oµÄ®¤n»¦´Ê ¸¤É ¸µ¦Äo Function)
FUNCTION FILES Example 12 Editor function x = ex12(A,b) C = A^2; d = b/2 x = C\b; Save as ex12.m Command Window L=[1 2;3 4]; v = [1 ; -1]; ex12(L,v)
FUNCTION FILES Example 13 Editor function [x,y] = ex13(a,b) x = (a+b)/2; y = sqrt(a*b); Save as ex13.m Command Window ex13(5,3) [out1,out2]=ex13(5,3)
CONTROL FLOW
IF-ELSE if (condition 1) (command 1) elseif (condition 2) (command 2) . . . else (command n) end
TRY-CATCH
SWITCH-CASE switch (variable) case (value 1) (command 1) case (value 2) (command 2) . . . otherwise (command n)
try (command 1) catch (command 2) end
end
CONTROL FLOW Example 14 Editor x = input('x = '); if x == 0 disp('command 1') elseif x> 0 & x <= 3 disp('command 2') elseif x > 3 disp('command 3') elseif x >= -3 disp('command 4') else disp('command 5') end
Save as ex14.m Command Window ex14 Try x= x= x= x= x=
0 1 5 -2 -5
CONTROL FLOW Example 15 Editor
Save as ex15.m
x = input('x = ');
Command Window
switch x case 1 disp('command case {2,3} disp('command case 'abc' disp('command case {'de','f'} disp('command otherwise disp('command end
ex15 1') 2') 3') 4') 5')
Try x= x= x= x= x= x=
1 2 ‘2’ ‘a’ ‘abc’ ‘f’
CONTROL FLOW Example 16 Editor function y = ex16(x) try
y = x+[1 2 3]; catch y=0 end
Save as ex16.m Command Window ex16(1) ex16(2) ex16([1 0 1]) ex16([3 2 1]) ex16([1 2;3 4])
CONTROL FLOW
FOR LOOP
WHILE-LOOP
for (variable) (command) end
while (condition) (command) end
break
°°µ¨¼oµÄ» 1 ¨¼
pause
®¥»µ¦Îµµªnµ´¤¸µ¦¸¥r
CONTROL FLOW Example 17 Editor n = input('n = '); s = 0; for k = 1:n s = s+k; end s
Save as ex17.m Command Window ex17 Try n= n= n= n=
3 1 0 -1
CONTROL FLOW Example 18 Editor
Save as ex18.m
n = input('n = '); s = 0; k = 1; while k <= n s = s+k; k = k+1; end s
Command Window ex18 Try n= n= n= n=
3 1 0 -1
INPUT AND OUTPUT FUNCTIONS input
³ª°³¬¦Ã¥´¦°°·¡»µ¸¥r °¦r¨oªÁÈnµÅªo
disp
¦µ¥¨´Á°¸¥
°³ªÂ¦ ®¦º°
o°ªµ¤nµ Ç
LOGICAL FUNCTIONS xor all any find isempty exist
exclusive or ¦ª°ªnµ¤µ·»³ªÅ¤nÁ} 0 ¦ª°ªnµ¤¸¤µ·°¥nµo°¥ 1 ³ªÅ¤nÁ} 0 ®µÎµÂ®n¸ÅÉ ¤nÁ} 0 ¦ª°ªnµÁ¤¦·r¤¸
µÁnµ³ 0 ®¦º°Å¤n ¦ª°ªnµ¤¸³ªÂ¦®¦º°¢{r³ÉºÉ°Á¸¥ª³¸É¦´»®¦º°Å¤n
LOGICAL FUNCTIONS Example 19 all([1 1 1 1 1]) all([1 0 1 1 1]) any([1 0 0 0 0]) any([0 0 0 0 0]) A = [2 5 3 9]; all(A>1) all(A>3 & A<=10) any(mod(A,2)==0)
B = [0 0 1 1;0 1 0 1]; all(B) all(B,1) all(B,2) all(all(B)) all(B(:)) find([1 0 1 0]) find(A>3) find(B) [x,y] = find(B)
NUMERIC FUNCTIONS fix
{Á¨
Ä®oÁ}εªÁȤ Ã¥{Á
oµ®µ 0
floor
{Á¨
Ä®oÁ}εªÁȤ Ã¥{Á
oµ®µ -f
ceil
{Á¨
Ä®oÁ}εªÁȤ Ã¥{Á
oµ®µ +f
round
{Á¨
Ä®oÁ}εªÁȤ Ã¥{Á
oµ®µÎµªÁȤ¸ÉĨo¸É »
abs
®µnµ³¤¼¦r
sign
®µÁ¦ºÉ°®¤µ¥ (+,-)
rem
®µÁ«¬µµ¦®µ¦
mod
modulo
COMPLEX NUMBER FUNCTIONS real
®µnª¦·
imag
®µnª·£µ¡
conj angle
®µ conjugate ®µ¤»¤Á¢Á}Á¦Á¸¥
EXPONENTIAL AND LOGARITHM FUNCTIONS ®µ¦µ¸É 2 ¥Îµ¨³µ e nµ log µ e nµ log µ 10
sqrt exp log log10
log2 sqrtm expm logm
nµ log µ 2 ®µ¦µ¸É 2 ÂÁ¤¦·r ¥Îµ¨³µ e ÂÁ¤¦·r nµ log µ e ÂÁ¤¦·r
TRIGONOMETRY AND HYPERBORIC FUNCTIONS sin
sine
asin
arcsine
sinh
hyperboric sine
asinh
hyperboric arcsine
cos
cosine
acos
arccosine
cosh
hyperboric cosine
acosh
hyperboric arccosine
tan
tangent
atan
arctangent
tanh
hyperboric tangent
atanh
hyperboric arctangent
csc
cosecant
acsc
arccosecant
csch
hyperboric cosecant
acsch
hyperboric arccosecant
sec
secant
asec
sech
hyperboric secant
asech
hyperboric arcsecant
cot
cotangent
acot
arcsecant arccotangen t
coth
hyperboric cotangent
acoth
hyperboric arccotangent
°·¡»Á}Á¦Á¸¥ STATISTICTIC FUNCTIONS min
®µnµÉε»
median
®µ¤³¥µ
cumsum
®µ¨¦ª¤´¤
max
®µnµ¼»
sort
Á¦¸¥
o°¤¼¨
cumprod
®µ¨¼´¤
range
®µ¡·¥³
sum
®µ¨¦ª¤
diff
®µ¨nµ¦´®ªnµ¤µ·³ª¸É ·³
mean
®µnµÁ¨¸É¥
prod
®µ¨¼
std
®µnªÁ¸É¥Á¤µ¦µ
STRING FUNCTIONS str2num
¨³ª°³¬¦Á}³ªÁ¨
bin2dec
¨Á¨
µ 2 Á} µ 10
num2str
¨³ªÁ¨
Á}³ª°³¬¦
dec2bin
¨Á¨
µ 10 Á} µ 2
strcmp
Á¦¸¥Á¸¥³ª°³¬¦
hex2dec
¨Á¨
µ 16 Á} µ 10
strcmpi
Á¦¸¥Á¸¥³ª°³¬¦ Ã¥º°ªnµ ³ª°³¬¦³ªÁ¨È³³ªÄ®nÁ®¤º°³
dec2hex
¨Á¨
µ 10 Á} µ 16
base2dec
¨Á¨
µ¸É ε®Á} µ 10
strfind
®µÎµÂ®n³ª°³¬¦µ¤¸Éε®
dec2base
¨Á¨
µ 10 Á}µ¸É ε®
STATISTICTIC FUNCTIONS Example 20 A = [2 5 3 9]; min(A) max(A) mean(A) sum(A) prod(A)
B = [1 2 1 3;2 4 1 0]; min(B) min(B,1) min(B,2) min(min(B)) min(B(:))
sort(A)
sum(B) sum(B,1) sum(B,2) sum(sum(B)) sum(B(:))
diff(A)
MATRIX FUNCTIONS zeros ones eye linspace logspace
¦oµÁ¤¦·r¤¸¤µ·Á} 0 ³Ê®¤ ¦oµÁ¤¦·r¤¸¤µ·Á} 1 ³Ê®¤ ¦oµÁ¤¦·rÁ°¨³¬r ¦oµÁªÁ°¦r
°¨Îµ³Á¨
· ¦oµÁªÁ°¦r
°¨Îµ³Á¦
µ·
length size fliplr flipud flipdim
®µªµ¤¥µª
°Á¤¦·r ®µ
µ
°Á¤¦·r ¨³Á¤¦·rÄ·«µ oµ¥-
ªµ ¨³Á¤¦·rÄ·«µ -¨nµ ¨³Á¤¦·rÄ·«µ¸É ε® ®¤»Á¤¦·r ±90q, ±180q,...
rand
¦oµÁ¤¦·r¤¸¤µ·Åoµµ¦»n¤ nµ 0-1 ¸É¤¸µ¦¦´µ¥Â Uniform
rot90 tril
¦oµÁ¤¦·rµ¤Á®¨¸É¥¤¨nµ
triu
¦oµÁ¤¦·rµ¤Á®¨¸É¥¤
randn
¦oµÁ¤¦·r¤¸¤µ·Åoµµ¦»n¤ n µ ¸É ¤¸ µ¦¦´µ¥Â Normal ¤¸ n µ Á¨¸É ¥ Á} 0 ¤¸ n ª Á¸É ¥ Á ¤µ¦µÁ} 1
det
®µ¸Á°¦r¤·Âr
°Á¤¦·r
inv
®µÁ¤¦·r³
¦oµÁ¤¦·r´Â¥ Á¨¸É¥
µ
°Á¤¦·r
pinv
diag reshape
rank
®µÁ¤¦·r³Á¤º° ®µÂ¦r
°Á¤¦·ªr
MATRIX FUNCTIONS Example 21 zeros(3,5)
B = [1 2 1 3;2 4 1 0];
ones(1,7)
length(B)
eye(5)
size(B)
diag([1 2 3 4])
reshape(B,4,2)
linspace(0,pi,20)
C = [1+i 1+2i ; 3-i 2];
rand(1,7)
C’
randn(1,7)
transpose(C)
SPARSE MATRIX FUNCTIONS sparse
¦oµ sparse matrix ¸ÉÁ} Á¤¦·r«¼¥r ®¦º° Á¨¸É¥¤µ·Äε®n¸ÉŤnÁnµ³ 0 spones ¨Á¤¦·r¦¦¤µÁ} sparse matrix Ä sparse matrix Ä®oÁnµ³ 1
speye
¦oµ sparse matrix ¸ÉÁ} Á¤¦·rÁ°¨³¬r
full
¨ sparse matrix Á}Á¤¦·r¦¦¤µ
SET FUNCTIONS unique union intersect
³¤µ·³ª¸É µÊÎ ³°°¡¦o°¤³Ê Á¦¸¥
o°¤¼¨ set union set intersection
setdiff setxor ismember
set difference set exclusive union ¦ª°µ¦Á}¤µ·
POLYNOMIAL FUNCTIONS roots
®µ¦µ
°¡®»µ¤
residue
®µ partial fraction
poly
®µ¡®»µ¤µ¦µ
polyder
®µ°»¡³ r
°¡®»µ¤
polyval
®µnµ
°¡®»µ¤
polyint
®µ·¥µ»¡³ r
°¡®»µ¤
polyfit
®µ¡®»µ¤¸É µ¼n°³³¸É ε® (¦´¤µ)
conv
¼¡®»µ¤
deconv
®µ¦¡®»µ¤
SET FUNCTIONS
Example 22 A = [2 3 4 2 4 3 1]; B = [0 3 5 3 2];
setdiff(A,B) setdiff(B,A)
unique(A)
ismember(A,B)
union(A,B) intersect(A,B)
CELL FUNCTIONS cell
¦oµ cell ªnµ
deal
ε®nµ³ªÂ¦Åo¸É¨´®¨µ¥³ª
iscell num2cell
¦ª°ªnµÁ}³ªÂ¦¦´Á£ cell ®¦º°Å¤n ®µ°»¡³ r
°¡®»µ¤
STRUCTURE FUNCTIONS struct
¦oµ structure
isfield
¦ª°ªnµ¤¸ºÉ° field ¸Éε®®¦º°Å¤n
isstruct
¦ª°ªnµÁ}³ªÂ¦¦´Á£ structure ®¦º°Å¤n
fieldnames
Á¦¸¥¼ºÉ° field Ä structure
getfield
Á¦¸¥nµ
° field Ä structure
setfield
ε®nµ
° field Ä structure struct2cell ¨ structure Á} cell
rmfield
¨ field
cell2struct
¨ cell Á} structure
SYMBOLIC FUNCTIONS sym,syms
¦oµ³ªÂ¦¦´Á£ symbolic
compose
®µ composite
° function
Ânµ³ªÂ¦ symbolic
diff
®µ°»¡³ r
sinplify
Á¨¸É¥Ä®o°¥¼nĦ¼¸É ³Ê ¸É »
int
®µ·¥µ»¡³ r
expand
¦´µ¥¡r°°¤µ
limit
numden
®µÁ«¬ ¨´ nª
fourier
Fourier Transform
Âo¤µ¦
laplace
LaplaceTransform
dsolve
Âo¤µ¦Á·°»¡³ r
ztrans
Z Transform
finverse
®µ inverse
° fnction
taylor
Taylor Series
subs
solve
®µ¨·¤·
plot
GRAPH DISPLAY FUNCTIONS polar µ¦¡¨È°¦µ¢Á·Áo x-y ¡¨È°¦µ¢Ä¦¼Á·
³Êª
axis
宨³¬´Â
pie
¦oµÂ£¼¤·ª¨¤
grid
 grid ®¦º°Å¤n
bar
¦oµÂ£¼¤·Ân
hold
¦¼Á·¤°¥¼n®¦º°Å¤n
stem
¡¨È°Ä¦¼
ª°·¤Á¡µr
xlabel
ε®Îµ°·µ¥Â x
hist
ylabel
ε®Îµ°·µ¥Â y
scatter
¡¨È°»Â¦´µ¥³ª
ε®®³ª
o°¦µ¢
contour
¦oµÁo contour
title legend
ε®ºÉ°
°¦µ¢Ân¨´Áo
¦oµ histogram
fill
¦´µ¥¸Ä®o¦¼ polygon
text
¡·¤¡r
o°ªµ¤Á¡·¤É Á·¤
ezplot
¡¨È°¦µ¢µ¢{r³É
line
ªµÁo¦Á¡·É¤Á·¤
figure
Ád®oµnµ¦¼£µ¡Ä®¤n
semilogx
Á®¤º° plot Ânµn Ä x Á} log µ 10
subplot
semilogy
Á®¤º° plot Ânµn Ä y Á} log µ 10
clf
loglog
Á®¤º° plot Ânµn Á} log µ 10 ³Ê 2 Â
close
Ân®oµnµ¦¼£µ¡ ¨¦¼Ä®oµnµ¦¼£µ¡ d®oµnµ¦¼£µ¡
GRAPHIC HANDLING FUNCTIONS get
°nµ handle
³Ê nµ handle
set
FILE INPUT AND OUTPUT FUNCTIONS fopen fgetl ÁdÅ¢¨r ¦³
o°¤¼¨Ä¦¦³n°Å fclose
fprintf
dÅ¢¨r
Á
¸¥
o°¤¼¨¨ÄÅ¢¨r
imread
IMAGE FUNCTIONS imagesc ¡¨È°¦¼Ã¥µ¦Îµ scaling
o°¤¼¨n° ¦³
o°¤¼¨¦´Á£¦¼£µ¡
imwrite
¦oµÅ¢¨r¦¼µ
o°¤¼¨
colormap
Á¨¸É¥Ã¸
¡¨È°¦¼
colorbar
¸Á¸¥nµ
image
AUDIO FUNCTIONS wavread
°nµ
o°¤¼¨µÅ¢¨r .wav
wavrecord
wavwrite
¦oµÅ¢¨rÁ¸¥µ
o°¤¼¨
wavplay
°³Á¸¥µ°»¦r°·¡» nÁ¸¥°°µ¨ÎµÃ¡