Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

MA T LA B

:
9 7 . 3 .0
9 7 . RAM
. RAM .

.

.
: ssljk07
E- mail : m atlab @lov ean gel.net
:

, , MAT LAB ,

http :/ / m atlabschool.com

[MAT LAB ]

: 10 0
: 2 0 0 1 10 6 () ~ 10

7 ()

: ( )
: 10 ~ 6 (12 ~ 1 , )
: MATLAB
( 8 0 % - 18 ,0 0 0 14 ,4 0 0 )
: 5 2 /
: ( 4 , 7 ) , ( 5 , 9 )
: , .
: http :/ / ma tla b s c ho o l.c o m/ s e m ina r.htm l

(10

6 )

1. ma tla b ove rview


2 . ma tla b .
3 . M file .
4 . Ma tla b .
5 . G UI p ro g ra m m ing
(10

7 )

1. Ha nd le G ra p hic s s ys te m .
2 . Ce ll a nd s truc t d a ta ty p e .
3 . G UI P ro g ra m m ing .
MATLAB 5 . x , 6 . x .
.

M A T LA B

High _lev el gr aphic fun ction s fig ur e , m atlab


. , w in dow
F igu re w in dow (a spect r atio) (r ect an gu lar
ax es ) . , a sp ect
r atio . .
, 2 .
t =[0:10:360]*(pi/ 180);
x =2*cos (t );
y =2*sin (t );
x lab el ('\ bf{x ax is }' ,'fon t size ' ,15 )
y lab el ('\ bf{y ax is }' ,' font size ' ,15)
title ('\ bf{ default r ect anu lar !}' ,'fon t size ' ,15 )
plot (x ,y )
[ 3 - 24] .

[ 3- 24] as pect ratio defa ult(, a uto )

[3 - 24] . ,
. , , a spect r atio
.
a sp ect r atio s qu a re , F ig ur e w in dow r ect an gu lar
.
ax is squ ar e

- 13 6 -

M A T LA B

[ 3- 25] as pect ratio squa re

[3 - 24] . , , F igu re
w in dow . , u nit s
.
, im ag e m atlab im a g e .m display
(a spect r atio ) , u nit s
. , a spect r atio e qu al , im a g e .
a spect r atio equ al im ag e ,
display im a g e .
, display t i g h t
. , im a g e e qu al ti g h t
.
ax is equ al

- 137 -

M A T LA B

[ 3- 26] as pect ratio equa l

ax is im ag e

- 13 8 -

M A T LA B

[ 3- 27] as pect ratio image

, display ax i s
e qu al ax i s im a g e a sp ect r atio .
(lin e ) , le g e n d
.

(sy n tax ): l e g e n d .m
a ) h =l e g e n d ( ' s t rin g 1 ' , 's t rin g 2 ' ,... )

leg en d .
b ) h =l e g e n d (h , 's t rin g s )
s t rin g s ()
.
c ) h =l e g e n d ( 'of f ' )
leg en d .
d ) h =l e g e n d ( ..., p o s )
p o s leg en d .
p o s [3 - 6] .

- 139 -

M A T LA B

leg en d

pos
-1

upper - rig ht corn er .

upper - left corn er .

low er - left corn er .

low er - rig ht corn er .

[Xlow erLeft Ylow erLeft]

n orm alized un it s .

[ 3- 6] lege nd.m pos lege nd

display leg en d m ou s e dra g g in g .


x =- pi:pi/ 20:pi;
plot (x , cos (x ), ' - r ' , x , sin (x ), ' - .b ' )
x lab el ('\ bf{x ax is }' ,'fon t size ' ,12)
y lab el ('\ bf{y ax is }' ,' font size ' ,12)
title ('\ bf{leg en d fu n ction }' ,'fon t size ' ,12)
h =leg en d ( ' cos ' , ' sin ' , 0);

[ 3- 28] lege nd.m pos=0

figu r e
.

- 14 0 -

s u b p lo t .m

M A T LA B

(sy n tax ) : s u b p lo t .m
s u b p lo t (m ,n ,p )
figu r e r ectan gu lar m n
.

subplot (m ,n ,p ) s u b plo t m n p .
x =- pi:pi/ 20:pi;
sub plot (1,2,1)
plot (x , cos (x ), ' - r ' )
x lab el ('\ bf{x ax is }' ,'fon t size ' ,12)
y lab el( '\ bf{y ax is }' ,'font size ' ,12)
title ( '\ bf{sub plot 121 }' ,'fon t size ' ,12)
sub plot (1,2,2)
plot (x , sin (x ), ' - .b ' )
x lab el ('\ bf{x ax is }' ,'fon t size ' ,12)
y lab el( '\ bf{y ax is }' ,'font size ' ,12)
title ( '\ bf{sub plot 122 }' ,'fon t size ' ,12)
[ 3 - 29] .

[ 3- 29] s ubplot.m

, , x

- 14 1 -

M A T LA B

. ,
. A x e s ob j e c t pr op erty n am e X D ir , Y D ir ,
ZD ir .
t =0:900;
subplot (121)
plot (t ,0.25 *ex p (- 0.05 *t ))
x lab el ('\ bf{x ax is }' ,'fon t size ' ,12)
y lab el ('\ bf{y ax is }' ,' font size ' ,12)
title ('\ bf{ x !}' ,'font size ' ,12)
subplot (122)
plot (t ,0.25 *ex p (- 0.05 *t ))
x lab el ('\ bf{x ax is }' ,'fon t size ' ,12)
y lab el ('\ bf{y ax is }' ,' font size ' ,12)
title ('\ bf{x !}' ,' font size ' ,12)
s et (g ca ,'x dir ' ,'r ev ' )
plot (t , 0.25 *ex p (- 0.05 *t ))
[ 3 - 30] .

[ 3- 30] x

y z ,
.
(ran g e ) display
.

- 14 2 -

M A T LA B

, A x e s ob j e c t property n am e X a x i s l o c at i on , Y ax i s lo c at i on x y
.
fig ur e y
, b ottom x , , y
, t op x .
pl ot .m pr operty n am e/ pr op erty v alu e
low _lev el g r aphic fun ction Lin e .m . , A x e s
o bj e c t .
[ 3 - 31] . , [ 3 - 32] [ 3 - 31]
M - file.

(sy nt ax ) : Lin e .m
h =lin e (x ,y ,z , 'pro p e rt y n am e ' , 'p rop e rty v alu e ' )
pr op erty n am e/ property v alu e x , y , z
.
, 2 x , y !

[ 3- 3 1]

- 143 -

M A T LA B

%
% [ 3 - 31] M - file.
%
% 1998.2.19
By Lim J on g_Su
%
clos e all
clear all
x 1=0:1/ 1000:1;
y 1=ex p (- 5 *x 1).*sin (200*x 1);
h l1=lin e (x 1,y 1,' color ' ,'r ' );
y 1_t ex t =y lab el( 'y 1 ' );
x 1_tex t =x lab el ('x 1 ' );
ax 1=g ca ;
s et (y 1_tex t ,'r ot ation ' ,0)
s et (ax 1,' x color ' ,'r ' ,'y color ' ,' r ' );
ax 2=ax es ( 'pos ' ,g et (ax 1,'p os ' ),'x ax islocation ' ,'t op ' , ...
'y ax islocation ' ,'right ' ,' color ' ,'n on e ' ,'x color ' ,'k ' ,'y color ' ,'k ' );
x 2=0+ep s :1/ 1000:.1;
y 2=cos (2*pi*10*x 2);
h l2=lin e (x 2,y 2,' color ' ,'k ' ,'parent ' ,ax 2);
y 2_t ex t =y lab el( 'y 2 ' );
x 2_tex t =x lab el ('x 2 ' );
s et (y 2_tex t ,'r ot ation ' ,0)
x lim it s =g et (ax 1,' x lim ' );
y lim it s =g et (ax 1,'y lim ' );
x in c =(x lim it s (2)- x lim it s (1))/ 10;
y in c =(y lim it s (2)- y lim it s (1))/ 10;
s et (ax 1,' x tick ' ,[x lim it s (1):x in c :x lim it s (2)],...
'y tick ' ,[y lim it s (1):y in c :y lim it s (2)])
g rid on
[ 3- 32] figure

g rid .
m atlab , , g rid o n/ of f
. , h old on/ off GUI
. , g ri d " .

- 14 4 -

M A T LA B

A x es Obj ect
pr operty n am e
x g ri d , y g rid , z g ri d
Gridlin e s t y l e

pr operty v alu e
grid .
"g rid " Lin e sty le .

t =0:1/ 1000:1;
b et a =200;
alph a =20;
y =ex p (- alph a *t ).*sin (b eta *t );
plot (t ,y )
x lab el ('\ bf{T im e [m sec]}' ,'fon t size ' ,12)
y lab el( '\ bf{A m plitu de }' ,' font size ' ,12)
title ( ' {\ bf{\ it e }^{- \ alph at }sin (\ b et at ) \ alph a < < \ b et a }' ,'fon t size ' ,12)
set (g cf,' color ' ,' w ' )
, [ 3 - 33] .
, x , y do t t e d lin e s t y le ( , :) g ri d
grid on
.
, dott ed lin e sty le g rid d e f au lt .
, a c tiv e f i g u re g ri d lin e ,
grid off
.

- 145 -

M A T LA B

[ 3- 33] grid sa mple

, x sty le - . g ri d .
[ 3 - 34] .
s et (g ca , 'x g rid ' , ' on ' , ' gridlin esty le ' , ' - .' )

[ 3- 34] x grid

, [ 3 - 34] fig ur e , [3 - 34]


h old on
. , [ 3 - 34] figu r e

- 14 6 -

M A T LA B

[ 3 - 34] figu r e . , fig ur e


. ,
h old off
fig ur e .
, A x e s Obj e c t , , n e x t pl o t pr operty n am e
.

) plot3.m : 1
pl o t3 .m 3 , z
p lo t .m .
t =0:.1:10*pi;
x =ex p (- t/ 20).*cos (t );
y =ex p (- t/ 20).*sin (t );
z=t ;
plot3 (x ,y ,z )
grid on
x lab el ('x ' );
y lab el( 'y ' );
zlab el (' z ' );
title ( '\ bf{' 'plot3.m ' ' fun ction !}' ,' font size ' ,12)
set (g cf,' color ' ,' w ' )
, [ 3 - 35] .

[ 3- 35] plot3.m"

, [ 3 - 35], z lab el x , y lab el . , z lab el


x , y lab el .

- 147 -

M A T LA B

x lab e l .m , y l ab e l .m , z la b e l .m t e x t ob j e c t h an dle .

T ex t Object
pr operty n am e

pr op erty v alu e
D e g re e s tex t strin g .

R ot at i on

d e f au lt =0
p ositiv e an gle .

h =zlab el (' z ' );


s et (h ,'r otation ' ,180);
z lab el x , y lab el .
, x , y , z lab el .
, A x e s Ob j e c t B ox pr operty n am e , on
Box . , off pr op erty v alu e B ox .
s et (g ca ,'b ox ' ,' on ' );
[ 3 - 36] z lab el Box

pr op erty n am e on .

[ 3- 36] la be l Box prope rtyna me

- 14 8 -

M A T LA B

2 s u rf .m , s u rf c .m , m e s h .m , m e s h c .m ,
m e s h z .m , v i e w .m , m e s h g ri d .m , c o lo rm ap .m , c ol o rb ar .m

. , 12 , 3 .
, c on t ou r .m [ 3 - 49] .
, [3 - 11] .

) contour .m : 1
c o n t o u r .m 3
.

(sy n tax ) : c o n t o u r .m
a ) [C , h ] =c o n t o u r (Z )
Z x - y .
Cont our C h an dle v alu e .
"c lab e l .m " la b e l .
b ) [C , h ] =c o n t o u r (Z , n )
Z n .
c ) [C , h ] =c o n t o u r (Z , v )
Z v .
d ) [C , h ] =c o n t o u r (X , Y , Z ) , [C , h ] =c o n t o u r (X , Y , Z , n (o r , v ) )
X , Y x , y .
e ) [C , h ] =c on t ou r (...., Lin e S p e c )
Lin eSpec .

c on t ou r .m , la b e l
. lab e l
c lab e l .m .
con tour lab el .
, c l ab e l .m lab el t e x t o bj e c t h an dle
s e t .m , g e t .m .
c l ab e l .m c o n t o u r m a trix . c on t ou r m at rix
cont our .m , con tour3.m , con t ou rf.m .

- 149 -

M A T LA B

(sy n tax ) : c l ab e l .m
a ) c la b e l (C , v )
con tour

m atrix , v lab el

lab el .
(b ) c l ab e l (C , 'm a n u al ' ) , c la b e l (C , h , 'm an u a l ' )
lab el m ou se
lab el .
re tu rn k ey lab elin g .

, clab el ,
.
Z=p eak s ;

%m atlab sam ple .

[c,h ]=con tour (Z);


s et (g cf,' color ' ,' w ' )
title ('\ bf{' ' con t ou r .m ' ' !}' ,'font size ' ,12)
[ 3- 49] .

[ 3- 49] contour.m

, [ 3 - 49] 5 .
[c,h ]=con tour (Z, 5 );
, [ 3 - 50] 5 .

- 15 0 -

M A T LA B

[ 3- 50]

, [ 3 - 50] lab el .
con _hn dl=clab el(c, h , ' m anu al ' );
, [ 3 - 50] [ 3 - 51] figu r e . ,
m ou s e k e y lab el .
lab elin g , re tu rn k ey .

con_hn dl=clab el (c, h , 'm an u al ' );


con tour h an dle
v alu e h lab el

. , h an dle v alu e h ,
+
lab elin g .

- 15 1 -

M A T LA B

[ 3- 51] la be ling

, 0.01 (- 10dB ) , , sty le


dott ed lin e (, :) .
[c,h ]=con tour (Z, [0.01 0.01], 'k - ' );
, ,
.

[0.01 0.01]

con _h n dl=clab el (c , h , 'm an ul ' )


Plea se w ait a m om ent ...
Car efully s elect cont ou r s for lab elin g .
W h en don e, pr es s RET U RN w hile th e Gr aph w in dow is th e activ e w in dow .
con _hn dl =
10.0021
, [ 3 - 52] . , lab el
m ou s e click .

- 15 2 -

M A T LA B

[ 3- 52]

, 0 .0 1 10 [dB ] . lab elin g


h an dle v alu e .
set (con_h n dl, ' strin g ' ,' 10[dB] ' );

[ 3- 53] la be ling

- 153 -

M A T LA B

, [2 4 6] . .
[c, h ]=cont our (Z, [2:2:6]);
clab el(c );
[ 3 - 54] .

[ 3- 54]

- 15 4 -

You might also like