Professional Documents
Culture Documents
Matlab 04
Matlab 04
:
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 )
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
[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 - 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
ax is im ag e
- 13 8 -
M A T LA B
, 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
n orm alized un it s .
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
, x sty le - . g ri d .
[ 3 - 34] .
s et (g ca , 'x g rid ' , ' on ' , ' gridlin esty le ' , ' - .' )
[ 3- 34] x grid
- 14 6 -
M A T LA B
) 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"
- 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 .
pr op erty n am e on .
- 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 ;
[ 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 .
. , h an dle v alu e h ,
+
lab elin g .
- 15 1 -
M A T LA B
[ 3- 51] la be ling
[0.01 0.01]
- 15 2 -
M A T LA B
[ 3- 52]
[ 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 -