[go: up one dir, main page]

0% found this document useful (0 votes)
17 views50 pages

Matlab 03

The document provides an overview of MATLAB, including its functionalities, syntax for M-files, and GUI programming. It details various commands and functions such as input handling, sorting, and dialog boxes. Additionally, it includes examples of code and explanations for creating interactive menus and message boxes.

Uploaded by

Sang-pyo Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views50 pages

Matlab 03

The document provides an overview of MATLAB, including its functionalities, syntax for M-files, and GUI programming. It details various commands and functions such as input handling, sorting, and dialog boxes. Additionally, it includes examples of code and explanations for creating interactive menus and message boxes.

Uploaded by

Sang-pyo Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

MA T LA B

:
97 . 3 .0
97 . RAM
. RAM .

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

: , , MAT LAB ,
http :/ / m atlabschool.com [MAT LAB ]
: 10 0
: 200 1 10 6 ( ) ~ 10 7 ( )
: ( )
: 10 ~ 6 (12 ~ 1 , )
: MATLAB
( 80% - 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

. M- file :

, M - file , M - file pro g ram m in g .I


.

1. input :

(sy nt ax ) : in pu t .m
(a ) "R =in p u t ( 'p rom p t ' , 's ' )"
"in pu t .m " , pro m pt ' strin g ,
.
,
R .
, .
(b ) "R =in p u t ( 'p rom p t ' )"
"in pu t .m " , pro m pt ' strin g ,
.
b a s e w ork sp ace
R .

:
x =2; y =3 ;
R =in pu t ( ' ! ' ,' s ' )
! test

R =

t est

R =in pu t ( ' ! ')


! x +y

R =

- 88 -
M A T LA B

, "in pu t .m " , , R =in pu t ( 'pro m pt ' ) ,


p rom pt M - files , .
, M - files p rom pt , in p u t .m
. R =in pu t ( 'p rom pt ' , 's ' )
(form at ) !

[ 18] (n um eric set ) ( , (ev ent ))


[ 2- 39] .
T =[2 0 7 7 9 4 5 8 0 1 5 7 0 4 1 4 7 6 9 8] .

[ 2- 39] [ 18]

[ 2- 39] di s p .m
. , (a s cen din g or der )
. , . m atlab
s o rt .m . .

- 89 -
M A T LA B

(sy n tax ) : s o rt .m
(a ) Y =s ort (X )
X (a scen din g order ) .
(b ) [Y , I] =s ort (X )
X (a scen din g order ) ,
X I .

:
X =[2 4 3 1];
[Y , I]=sort (X )
Y =

1 2 3 4 % X

I =

4 1 3 2 % X

, , X , (colu m n ) ,
, X , . ,
[ 18] M - file .

, T ,
(fun ction m ode M - file ) [ 2- 39]
(form at ) M - file (script m ode M - file ), M - file
.

script m ode M - file fun ction m ode M - file M - file


.

, function m ode M - file [ 2- 40a] .


c s ort .m .

- 90 -
M A T LA B

f u n c t i o n d = c s o r t (T )
%
%CSORT T .
%
% 1993 . 8 . 4 By Pa u l E . Pf e i f f e r
% 1998 . 2 . 7 mo d i f i e d b y Li m J o n g_ Su
%

T=T ( : ) ' ;
P=o n e s (s i z e (T ) ) ;
D = [T ; P ] ;
[Y, I ] = s o r t (T ) ;
X = D( : , I ) ;
m = l e n g t h (T ) ;
TI = X ( 1 , : ) ;
PI = X (2 , : ) ;
j = 1;
t ( 1 ) = TI ( 1 ) ;
p ( 1 ) = PI ( 1 ) ;
f o r i = 1 : (m - 1 )
i f a b s (TI (i ) - TI (i + 1 ) ) < 1e - 6 % 1e - 6
j = j ; % .
p (j ) = p (j ) + PI (i + 1 ) ;
el se
j = j +1 ;
t (j ) = TI (i + 1 ) ;
p (j ) = PI (i + 1 ) ;
end
end
d = [t ; p ] ;

[ 2- 40a] csort.m

, 13 , , X = D(: ,I ) ; pag e20


. .
[ 2- 40b ] c s ort .m [ 2- 39] scr een
s cript m ode M - file .
f re q .m . di s p .m .

- 91 -
M A T LA B

%
%FREQ cs or t .m l i st .
%! : cs or t .m .
%
% 1993 . 8 . 4 By Pa u l E . Pf e i f f e r
% 1998 . 2 . 7 mo d i f i e d b y Li m J o n g_ Su
%

T = i n p u t ( ' Li s t ! :');
n = l e n g t h (T ) ;
H = c s o r t (T ) ' ;
A = [H H ( : , 2 ) / n ] ;
di sp ( ' ' ) % !
d i s p ( [ ' Li s t : ' , n um2 s t r (n ) ] )
di sp ( ' ' )
di sp ( ' ')
d i s p (A )

[ 2- 40b] freq .m script mode M - file

, ,
. , , , ,
. , pro f e s s io n al
m at la b 2 1 ,
.

- 92 -
M A T LA B

2. m enu .m :

(sy nt ax ) : m e n u .m
"R =in pu t ( 'm e n u t it l e ' , ' 1 ',' 2 ' , ... , ' 3 ' )"
'm e n u tit le ' m en u w in dow .
1 , ... , 2 pu s h " lab el .
pu s h " click
n .

[ 19] t = - 2 *pi :1/ 10 0 :2 *pi , y =s in (t ) , m e n u .m


re d , g re e n , b lu e , plo t .m (plot )
.
, y .

[ ]
in p u t .m b re ak .m .

[ 2- 41] M - file .
e x 2_ 16 .m .

l o w e r .m .
u pp e r .m .

- 93 -
M A T LA B

%
% me n u . m .
%
%1 9 9 8 . 2 . 4 By Li m J o n g_ Su
%

l i n e_ c ol o r = [ ' r ' , ' g ' , ' b ' ] ;


st r='y ' ;

t =- 2 *p i : 1 / 1 0 0 : 2 *p i ;
y = s i n (t ) ;

wh i l e ( 1 )
i f s t r == ' y '
k=me n u ( ' ' , ' r ed ' , ' gr een ' , ' bl ue ' ) ;
p l o t (t , y , l i n e _ c o l o r (k ) )
R=i n p u t ( ' ' 'y' ' t yp e ! : ' , ' s ' ) ;
s t r =l owe r (R) ;
el se
br eak;
end
end

cl os e al l

[ 2- 41] ex 2_16.m "

[ 2- 42a ] e x 2_ 16 .m com m an d w in dow .

[ 2- 42a] "ex 2_16.m " command window

- 94 -
M A T LA B

[ 2- 42b ] e x 2_ 16 .m , m e n u w in d o w .
pu sh click , .

[ 2- 42b]

[ 2- 42c] e x 2_ 16 .m , pl o t , m en u w in dow re d
click .

[ 2- 42c] "ex 2_16.m " plot .

com m an d w in dow p rom pt y ty pe .

- 95 -
M A T LA B

3. dialog (type) :

dialog , .
, , qu e s t dlg .m m s g b ox .m .

dialog .
h e lp dlg , in pu t dl g , p a g e dl g , prin t dl g , e rro rdl g , w a rn dl g

dialog dialog
. , e rror
. , dialog
!

(sy n tax ): qu e s t dlg .m


R = qu e s t dl g ( 'q s t rin g ' , 't it l e ' , 's t r 1 ' , 's t r2 ' , 'd e f au lt ' )
dialog b ox ,
's tr 1 ' , ' s t r2 ' lab els pu sh .
"default " default .
defau lt 's t r 1 ' , 's tr2 ' .
str .
' str ' R .

(sy n tax ): m s g b o x .m
m s g b ox (m e s s a g e ,t itl e , 'i c o n ' )
t itl e b ox , m e s s ag e b ox .
m e s s ag e box ic on .

"m s g b ox .m " icon :


icon 3 , 'e rror ' , 'h e lp ' , 'w arn ' .
.

[ 2- 43] "msgbox .m " icon

- 96 -
M A T LA B

[ 2 0] [ 16] in pu t .m qu e s t dlg .m
.

[ ]
[ 2- 44] e x 2_ 17 .m . .

%
% me n u . m, quest dlg .m .
%
%1 9 9 8 . 2 . 4 By Li m J o n g_ Su
%

l i n e_ c ol o r = [ ' r ' , ' g ' , ' b ' ] ;


s t r = ' Ye s ' ;

t =- 2 *p i : 1 / 1 0 0 : 2 *p i ;
y = s i n (t ) ;

wh i l e ( 1 )
i f s t r cmp (s t r , ' Ye s ' )
k=me n u ( ' ' , ' r ed ' , ' gr een ' , ' bl ue ' ) ;
p l o t (t , y , l i n e _ c o l o r (k ) )
s t r =q u e s t d l g ( ' ?', ' ' , ' Ye s ' , ' No ' , ' No ' ) ;

el se
br eak;
end
end

cl os e al l

[ 2- 44] ex 2_17.m

[ 2- 45] e x 2_ 17 .m qu e s t dl g .m w in dow .
Y es .

[ 2- 45]

- 97 -
M A T LA B

[ 2 1] pa g e51 [ 2] p m _ c .m e rro r .m m s g b o x .m
.

[ ]
pm _ c .m , . , pm _ c .m
, m s g b o x .m .

[ 2- 46] pm _ c b .m .

f u n c t i o n PM_ c b (x )

% , M- f i l e .
%
%1 9 9 8 . 2 . 4 By Li m J o n g_ Su

i f x ~=a b s (x )
ms gb o x ( ' .', ' ' , ' e r r or ' ) ;
r et ur n ;
% e r r or ( ' . ');

e l s e i f x ~= f i x (x )
ms gb o x ( ' .', ' ' , ' e r r or ' ) ;
r et ur n ;
end

y = r e m (x , 2 ) ;

s wi t c h y
ca s e 0
di sp ( ' !' );
o t h e r wi s e
di sp ( ' !' );
end

[ 2- 46] pm _c b .m

- 98 -
M A T LA B

[ 2- 47] m s g b o x .m b ox ,
b ox .

pm _cb (- 2)

[ 2- 47]

4. :

.
.

(sy nt ax ) : fliplr .m
"B =f liplr (A )"
A .

: X =[2 5 1 8 3];
Y =fliplr (X )
Y =

3 8 1 5 2

f lipu d .m .

- 99 -
M A T LA B

. P- code Files : matla b5.0

, M - file ,
. , ,
, . ,
p c o d e .m . M - file s p a r s in g .

p a r s in g ( )

.
(par sin g ) .

m atlab M - file s par sin g p s e u d o c o de


.

p s e u d o c o de ( )

.
.

"p c o d e .m " M - files ps eu doc ode .p P - file s


. , P - files M - files m atlab . , p - code , M - file s
par sin g p ar sin g . , M - files
.
, m atlab p ar sin g P - files M - files
. , GUI P - files
.

(sy n tax ) : p c o d e .m
(a ) "p c o de f u n 1 f u n 2 ..."
1, 2 p - files .
(b ) "p c o de * .m "
, M - files p - files .

- 10 0 -
M A T LA B

[ 2- 48] [ 21] p m _ c b .m p - file


.

[ 2- 48] pm_cb .m pm_cb .p

[ 2- 48] p c o d e pm _ c b .m com m an d w in dow


p m _ c b .p . , pm _ c b .m . ,
, P - files .

- 10 1 -
M A T LA B

M ath w ork s m atlab H an dle Graph i c s


sy stem . , s cr een
(fig ur e w in dow ) pat ch ( ) g raph i c s o bj e c t
. , lin e, t ex t , im ag e, u ser in terface contr ols , , u s er int erfa ce
pu lldow n m en u s g ra ph i c s ob j e c t .
g ra ph ic s o bj e c t s 9 , H an dle Gr aph ics sy st em
.
[ 3 - 1] g raph i c s o bj e c t s .

(a) figure object (c) Line object

(b ) Ax es object (d) P atch object

- 10 2 -
M A T LA B

(e) Surface object (g ) T ext object

(f) Image object (h ) Uicontrol object

(i) Uimenu object

[ 3- 1] matlab object .

object ( .)
, m atlab 3 . , 3
(h i e rarc h y ) .
GUI , ,
.

- 103 -
M A T LA B

, , ,
.
[ 3 - 2] [ 3 - 1] .

[ 3- 2] matlab

, [ 3 - 1] [ 3 - 2] , . , [ 3 - 2]
, Root lev el . lev el
m atlab gr aphics . , [
3 - 2] R o ot , F ig ur e, A x e s ,
Uim en u , . , gr aphics
R o ot ? .

R o ot , s c re e n . , scr een
, , .
, lev el lev el . ,
lev el , lev el . , A x es F igu re
.

.
1) m atlab .
2) .
3) . ,
.
4) lev el (siblin g s ) .

! , .

, ,
,
!

- 10 4 -
M A T LA B

I. H an dle Gr aphics .

m atlab ,
. h an dl e .
h a n dle figu r e obj ect , lev el
(floatin g p oint nu m b er ) .

h_fig =fig ur e

h_fig =

h_fig 1 . , fig ur e , figu re


. , 1 figu re h an dle v alu e .
[ 3 - 3] figu r e , fig ur e .

[ 3- 3] figure

[ 3- 3] F i g u re N o . 1 . , 1 h _fig 1
. , h _fig 2=fig ur e (2) , F i g u re N o . 2
fig ur e .

, h an dle v alu e h an dle v alu e ,


h an dle v alu e . , h an dle v alu e
. , . , R oot object
h an dle v alu e 0 . , m atlab gr aphics scr een
.

- 105 -
M A T LA B

, m atlab h an dle object (t erm )


. , h an dle obj ect
.

, h an dle (pro p e rt y n am e ) s e t .m
(pro p e rt y v a lu e ) g e t .m
.

: s e t .m
"s e t (h an dl e , pro p e rt y n a m e , p rop e rt y v alu e )"
h an dle pro p e rt y n a m e
pro p e rt y v alu e .

: g e t .m
"p rop e rt y v alu e =g e t (h an dl e , pro p e rt y n am e )"
h an dle pro p e rt y n a m e
pro p e rt y v a lu e .

close all % figu re (a c tiv e f i g u re ) .


h _fig 1=fig ur e (1)

h_fig 1 = % F ig u re N o . 1 fig ur e .

[ 3 - 4] F ig u re No. 1 n u m b e rtit le . ,
n u m b e rtit le fig ur e p rop e rt y n a m e , F ig u re No. 1
pro p e rty v alu e .

, fig ur e (pro p e rt y n am e ) n u m b e rt itl e


pro p e rty v alu e F ig u re N o . 1 .

- 10 6 -
M A T LA B

[ 3- 4] numbertitle Figur e No. 1

, F i g u re N o . 1 B y Lim Jon g _ S u . ,
pr operty n am e nu m b ertitle , (n am e ) B y Lim Jo n g _ S u
. , n um b ertitle n am e pr op erty n am e
.

2 .

. pr operty n am e nu m b ertitle pr op erty v alu e off .


. pr operty n am e n am e property v alu e
By Lim J on g_Su .

pr operty n am e n u m b e rtit le pr operty v alu e off


n on e , n o, error .

? ?? Err or u sin g ==> s et


B ad v alu e for figu re pr operty : ' Num b erT itle ' .

, n u m b e rt it le property v alu e
on , off .

pr operty n am e pr op erty v alu e s e t .m


.

set (h _fig 1,'nu m b ertitle ' ,' off ' ,' n am e ' ,'By Lim Jon g _Su ' )

h_fig 1 figu r e h an dle


n u m b e rtit le , n am e fig ur e pr operty n am e
o ff , B y Lim Jo n g _ S u fig ur e pr operty v alu e

- 107 -
M A T LA B

, figu r e F i g u re N o . 1 B y Lim Jon g _ S u .


[ 3 - 5] .

[ 3- 5] name By Lim Jong_Su

, h an dle h_fig 1 figu r e , .

h _size =g et (h_fig 1,'position ' )

h_size =

189 304 390 246

pr operty n am e pr operty v alu e set .m


g et .m .

figu r e pr operty n am e property n am e ,


pr op erty n am e pr op erty v alu e . , [ 3 - 1]
, .
, m atlab GU I ,
pr op erty n am e pr op erty v alu e .
, figu r e pr operty n am e pr operty v alu e
?

- 10 8 -
M A T LA B

set (h _fig 1)
Backin g St or e : [ {on } | off ]
CloseR equ estF cn
Color
Colorm ap
Curr en tA x es
Curr en tObject
Curr en tP oin t
Dith erm ap
Dith erm apM ode : [ aut o | {m an u al} ]
Int eg erH an dle : [ {on } | off ]
Inv ertH ar dcopy : [ {on } | off ]
K ey Pr es sF cn
M en uBar : [ n on e | {fig ur e } ]
M in Colorm ap
N am e
N ex tPlot : [ {a dd } | r eplace | r eplacechildr en ]
Nu m b erT itle : [ {on } | off ]
P ap erUnit s : [ {in ch es } | centim et er s | n orm alized | point s ]
P ap er Orien tation : [ {portr ait } | lan d scap e ]
P ap erP osition
P ap erP ositionM ode : [ au to | {m anu al} ]
P ap erT y pe : [ {u slett er } | u sleg al | a3 | a4letter | a5 | b4 | t abloid ]
P oin ter : [ cr os sh air | fu llcr os sh air | {arr ow } | ib eam | w at ch | t opl | topr | b otl |
b otr | left | t op | right | b ottom | cir cle | cr os s | fleur | cu st om ]
P oin ter Sh apeCDat a
P oin ter Sh apeH ot Spot
P osition
Ren der er : [ {p ain t er s } | zbuffer ]
Ren der erM ode : [ {aut o } | m an u al ]
Resize : [ {on } | off ]
ResizeF cn
Sh ar eColor s : [ {on } | off ]
Un it s : [ in ch es | cen tim eter s | n orm alized | poin t s | {pix els } ]
W in dow ButtonD ow n F cn
W in dow ButtonM otionF cn
W in dow ButtonU pF cn
W in dow Sty le : [ {n orm al} | m odal ]
Bu tt onDow nF cn
Childr en
Clippin g : [ {on } | off ]
Cr eat eF cn

- 109 -
M A T LA B

DeleteF cn
Bu sy A ction : [ {qu eu e } | can cel ]
H an dleV isibility : [ {on } | callb ack | off ]
Int erruptible : [ {on } | off ]
P ar en t
S elected : [ on | off ]
S election H ig hligh t : [ {on } | off ]
T ag
U serData
Visible : [ {on } | off ]

, . fig ur e pr operty n am e
pr op erty v alu e , [ 3 - 1] 8
pr op erty n am e pr op erty v alu e , 9 pr operty n am e pr operty v alu e
. ,
m atlab GUI C ++ .

, p rof e s s i on al m a tl ab 2 1
GUI . ,
m atlab GUI .

II. L ow _lev el fu n ction s .

high lev el fun ction ( : plot .m , m esh .m etc )


, M atlab gr aphics sy st em
h an dles low _lev el fu n ction s M atlab g r aph ic
low _lev el fu n ction s
.
low _lev el fun ction s (Object ) M atlab gr aph ic ,
low _lev el gr aph ic fun ction s h ig h_lev el gr aphic fun ction s
, , gr aph ic fun ction s .
H an dle Gr aphic fu n ction s low _lev el fu n ction s [ 3 - 1]
, 9 . 9
. ,
pr operty n am e pr operty v alu e ,
. , . , M atlab
h elp HT ML , P DF
.

- 110 -
M A T LA B

,
. , GU I
. , s e t .m g e t .m ,
.

. Root Object

Root Object . , low _lev el fun ction s


pr op erty n am e/ property v alu e pair s , M atlab com m an d w in dow
.

R oot Object , object


, M atlab m an u al , GUI
, pr operty n am e/ pr op erty v alu e
.

set (0)

Root Object . , figu re object


h an dles v alu e . , Root Object h an dle v alu e
0 ! , com m an d w in dow display Root Object
, .
.

*Diary : [ on | off ] .......................... ( 1)


*Sh ow Hidden H an dles : [ on | {off } ] .......................... ( 2)

( 1) ( 2) [ ] pr operty n am e ( diary Sh ow Hidden H an dles


.) ( , pr operty v alu e ) . ,
pr operty n am e ,
on , off . , ( 2) { } of f
(pr operty v alu e ) , d e f au lt pr op erty v alu e . , M atlab
pr operty v alu e . , set .m defau lt
pr operty v alu e .

g et (0,'u nit s ' ) %pr operty n am e u nit s pr operty v alu e


% g et .m .
an s =
pix els %pr op erty n am e un it s
% defau lt pr operty v alu e .
% u nit s fig ur e object .

- 1 11 -
M A T LA B

s et (0,'un it s ' ,' n or ' ) % pr op erty v alu e n or set .m


% .
g et (0,'u nit s ' ) % "pr operty v alu e .

an s =

n orm alized

pr op erty n am e , , n orm alized


n or . , n or
pr operty n am e . ,
pr operty n am e , ,
err or .

( 1) M atlab { } . ,
{ } . M atlab
pr operty n am e defau lt pr operty v alu e . M atlab
h elp m an u al . , ( 1) Diary : [on | {off }]
.

A u t om aticF ileUpdat es Bu tt on Dow nF cn


. property n am e u n iv e r s a l
pro p e rt i e s . , object pr operties . ,
Bu tt on Dow nF cn , form at ( strin g ,
n um b er ) . object Root Object
pr op erty n am e .

.............. ................
A ut om aticF ileUp dat es : [ on | off ]

Butt on Dow n F cn
............. ....................

- 112 -
M A T LA B

. figure object

h =figu r e

h =

, [ 3 - 6] figu r e obj ect .

[ 3- 6] origin al figure

, [ 3 - 6] [ 3 - 7] .

- 1 13 -
M A T LA B

[ 3- 7] figure

, [ 3 - 6] , n um b ertitle (property v alu e off ),


n am e By Lim J on g_Su . , fig ur e fig ur e
icon .

figu r e , re s i z e pr op erty n am e .
[{on } | off] .
s e t .m
.

s e t .m g e t .m h an dles , .

s et (h ,'n um b ertitle ' ,' off ' ,'n am e ' , ... % " ... " ?
'By Lim e J onfg_Su ' ,'m enu b ar ' ,'n on e ' ,'r esize ' ,' off ' )

[ 3 - 6] fig ur e , M atlab un it s
.

fig_size =g et (h )

fig_size =

165 114 470 279

g et (h ,' un it s ' )

an s =
pix els

- 114 -
M A T LA B

fig ur e object pr operty n am e position (


: pos ) .

M atlab figu re . , [le f t


b o t t o m w idt h h e ig h t ] .

GUI , slider , r adio bu tton , pu sh butt on


. , .
[ 3 - 8] .

[ 3- 8] figur e

, [ 3- 6] fig _size .

Left 165
Bottom 114
w idth 470
H eigh t 279

[ 3- 1] figure

M atlab u nit s 5 .

a )in c h e s b )c e n t im e t e r s c )n o rm ali z e d d )p o in t s e ){p ix e l s }

- 1 15 -
M A T LA B

, M atlab un it s w in dow ([ 3 - 8] )
, N orm alized u nit s (0,0) , (1.0
1.0) .
un it s .

u nit s p o in t s 1/ 72in ch es .

. Axes object

, ! ,
, h an dle v alu e fu n ction s .

1. g cf (g et cu rrent figu r e ) : activ e fig ur e h an dle .

a ctive
, fig ur e , m ou s e
figu r e . m ou s e figu r e
n um b ertitle , ( [3 - 8] ) a c t iv e
.
figu re activ e
.

2. g ca (g et curr en t ax es ) : activ e fig ur e ax es h an dle s


.

t =- 2*pi:1/ 100:2*pi;
y =sin (t );
plot (t ,y )

, [ 3 - 9] fig ur e .

- 116 -
M A T LA B

[ 3- 9] sample figure

[ 3 - 9] lin e .

A x es Object
property n am e property v alu e
x lim , y lim , zlim .

set (g ca ,'x lim ' , [m in (t ) m ax (t )],'y lim ' ,[- 1.5 1.5])
% , .

[ 3- 10] sample figure

- 1 17 -
M A T LA B

3. g co (g et curr ent obj ect ) : activ e figu r e , m ou se


h an dle .

t =- 2*pi:1/ 100:2*pi;
y 1=sin (t );
y 2=cos (t );
plot (t ,y 1,'k ' ,t ,y 2,'k ' ) % 'k ' .
% plot .m .

s et (g ca ,'x lim ' , [m in (t ) m ax (t )],'y lim ' ,[- 1.5 1.5])

[ 3- 11] sample figure

[ 3- 11] , ,
. ,
m ou se .

m ou se ,
5 pix les . 5 pix els
, .

, , . ,
. ,
.

Lin e Object
pr operty n am e pr operty v alu e
Co lo r .
Lin e w i dth n um b er

- 118 -
M A T LA B

set (g co,' color ' ,'r ' ,'Lin ew idth ' ,15 )

, [ 3 - 11] [ 3 - 12]
. b u t t o n do w n property n am e GUI
.

[ 3- 12] gco

, M atlab h old on/ off . ,


, .
, GUI .

A x es Object
property n am e property v alu e
, add h old on
N e x t pl ot
, r eplace , h old off .

t =- 2*pi:1/ 100:2*pi;
y 1=sin (t );
y 2=cos (t );
plot (t ,y 1,'r ' )
set (g ca ,'n ex tplot ' ,' add ' ,'x lim ' ,[m in (t ) m ax (t )])
plot (t ,y 2,'b :' )

, [ 3- 13] .

- 1 19 -
M A T LA B

[ 3- 13] Ax es Object nex tplot

figu r e obj ect n ex tplot " !

. text object :

u icontr ol, u im en u object s , object s


GU I . , lin e, path , im a g e, su rface,
ligh t object s . im ag e object object s
in terface , , .

[ 3 - 1] (g )t ex t object , M atlab
. sy m b ol . ,
t e x t .m .

(sy nt ax ) : t e x t .m
(a )"t e x t _ h a n dl e =t e x t (x ,y , 's t rin g ' )"
, (x ,y ) "strin g " display .
(b )"t e x t _ h a n dle =t e x t (x ,y ,z , 's trin g ' )"
, 3 (x ,y ,z )
"strin g " display .
(c )"t e x t _ h a n dle =t e x t (x ,y ,z , 'p rop e rty n am e ' , 'pro p e rt y v alu e ' )"
(x ,y ,z) , .
2 (x ,y ) .

- 12 0 -
M A T LA B

t e x t .m sy m b ol
.

[ 3 - 14] .

[ 3- 14] symbol

[ 3 - 14] .

t =0:900;
plot (t ,.25*ex p (- .005*t ))
h =tex t (300,.25 *ex p (- .005 *300),...
'\ bullet\ left arrow\ fontn am e{tim es }0.25{\ it e }^{- 0.005{\ itt }} .at {\ itt }=300 ' );

"\ b u ll e t , \ l e f t a rro w " [ 3 - 2] .

- 12 1 -
M A T LA B

[ 3- 2]

L at e x , tex t object int erpr et er tex


.

- 12 2 -
M A T LA B

g et (h ,'in terpr eter ' )

an s =

t ex

, , strin g ' , ty pin g


fig ur e display .

set (h ,' in terpreter ' ,'n on e ' )

, fig ur e display font .

h =tex t (300,.25 *ex p (- .005 *300),...


'\ bullet\ left arrow\ fontn am e{tim es }0.25{\ it e }^{- 0.005{\ itt }} .at {\ itt }=300 ' );

font fon t
\ bf Bold F ont
\ it it alics fon t
\ sl obliqu e font ( )
\ rm n orm al fon t
\ f o n t n am e (f o n tn am e } fon t font

[ 3- 3] font

{ } .
, _ , ^ .

\ , {, }, _ , ^ \ display .
,
\ \ , \ {, \ }, \ _ , \ ^ .

.
[ 3 - 15] sam ple figu r e .

- 123 -
M A T LA B

[ 3- 15]

(strin g ) pr operty n am e H o ri z o n t a lA li g n m e n t ,
V e rti c a lA lig n m e n t 2 .
[ 3 - 4] [ 3- 16] .

T ex t Object
p rop e rt y n a m e pr operty v alu e
H o riz o n t alA lig n m e n t {left } | cen ter | rig ht
V e rt ic alA li g n m e n t t op | cap | {m iddle } | b a selin e | Bott om

[ 3- 4]

[ 3 - 16 (a )] H o ri z on t alA li g n m e n t , [ 3 - 16 (b )]
V e rti c a lA lig n m e n t .

(a) "HorizontalAlignment " .

- 12 4 -
M A T LA B

(b) "VerticalAlignment " .

[ 3- 16]

, "T e x t .m " ,
. ? ,
m a th w o rk s .c o m .
, .

M atlab

m ou s e click
zoom on .
.
zoom off Zoom .
x .
z o om x on
m ou se zoom on .
x .
zoom y on
m ou se zoom on .
zoom out figu r e .

[ 3- 5]

[ 3- 5] z o o m .m , [ 3 - 15] (dot )
. , .

[ 3 - 4] [ 3 - 16] , [ 3 - 15] M - file


.

[ 3 - 17] [ 3 - 15] , M - file .


f i g 3 _ 17 .m .

- 125 -
M A T LA B

%
%[ 3- 15 ] , M- f i l e .
%" t e x t . m" .
%
%1 9 9 8 . 2 . 1 8 By Li m J o n g_ Su
%

cl os e al l
cl ea r al l

t = 0 : p i / 1 0 0 : 2 *p i ;
y = s i n (t ) ;
p l o t (t , y )
x l ab e l ( ' t = 0 t o 2 \ p i ' , ' f on t s i ze ' , 16 )
y l a b e l ( ' s i n (t ) ' , ' f o n t s i z e ' , 1 6 )
t i t l e ( ' \ i t {Va l u e o f t h e Si n e f r om Ze r o t o Two Pi } ' )
s e t (g c f , ' c o l o r ' , ' w ' )
t e x t (3 *p i / 4 , s i n (3 *p i / 4 ) , ' \ b u l l e t \ l e f t a r r ows i n (t ) = 0 . 7 0 7 ' )
s e t (g c a , ' n e x t p l o t ' , ' a d d ' )
p l o t (3 *p i / 4 , s i n (3 *p i / 4 ) , ' r o ' )
t e x t (p i , s i n (p i ) , ' \ l e f t a r r ows i n (t ) = 0 ' )
t e x t (5 *p i / 4 , s i n (5 *p i / 4 ) , . . .
' s i n (t ) =- 0 . 7 0 7 \ r i g h t a r r ow ' , ' Ho r i z o n t a l a l i g nme n t ' , ' r i g h t ' )
s e t (g c a , ' n e x t p l o t ' , ' r e p l a c e ' )

[ 3- 17] fig3_17.m

, figu r e Object , A x es Obj ect Lev el defau lt


pr operty v alu e , fig 3_17.m
s e t (g c a , ' n e x t p l o t ' , ' r e p l a c e ' ) , default
pr operty v alu e !
, , A x es Object
Lev el A x e s lev el
.

M atlab Gr aphics sy st em H an dle g raphics Low _Lev el


fu n ction s .

, H ig h_lev el fu n ction s !

- 12 6 -
M A T LA B

. High_leve l functions .

High _lev el fun ction s display


.
, Low _lev el fu n ction s
display , property n am e / property v alu e ,
(ax is s calin g ) (Lin e color ) .

3
.

1. .
"pl ot .m , plo t 3 .m , c on t ou r .m , c on t ou r3 .m , c on t ou rf .m , c la b e l .m , s t e m .m ,
s t e m 3 .m , s t air s .m , c om p a s s .m , f e at h e r .m , c o m e t .m , c o m e t3 .m ,s c at t e r .m ,
s c at t e r3 .m , p o lar .m , ro s e .m , "

2. 3 .
"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 orb ar .m "

3. .
"pi e .m , pi e 3 .m , b a r .m , b arh .m , b ar3 .m , b a r3 h .m , are a .m , e rrob ar .m , e z pl ot .m "

, "l e g e n d .m , s u b pl o t .m , "
. , .
, .

, .

1. :

) plot .m : 1

plot .m . ,
.

- 127 -
M A T LA B

(Sy n tax ) : pl o t .m
a ) plo t (Y )
, Y , x Y in dex , y Y
. , Y , x r eal (Y ), y
im ag (Y ) .
b ) plo t (X 1 ,Y 1 ,... )
X1 Y1 lin e .
c ) plo t (X 1 ,Y 1 ,Lin e S p e c ,...)
Lin eSpec color , lin e sty le, m ak er sty le
.
d ) pl o t ( ..., 'P ro p e rt y N a m e ' ,P ro p e rt y V alu e ,...)
"Lin e"object pr operty n am e/ pr operty v alu e sty le
.
e ) h = plo t (...)
Lin e , Lin e
h an dle v alu e .

X =[1:10; 0.7 *[1:10]; 0.5 *[1:10]; 0.25 *[1:10]) ' ;


plot (X )
x lab el ('x ax is ' ,' font size ' ,15)
y lab el (' y ax is ' ,'fon t size ' ,15 )
title ('\ bf{' 'plot .m ' ' }' ,' font size ' ,15)

- 12 8 -
M A T LA B

[ 3- 18] "plot .m "

[ 3 - 18] X Y , X
in dex X .( , x =1:len gth (X ))

, (lin e ) ty p e , default
.
default .

Lin e_Color =g et (g ca ,' coloror der ' )

Lin e_Color =

0 0 1.0000
0 0.5000 0
1.0000 0 0
0 0.7500 0.7500
0.7500 0 0.7500
0.7500 0.7500 0
0.2500 0.2500 0.2500

, ty p e defau lt .

- 129 -
M A T LA B

Lin e_T y pe =g et (g ca ,'Lin esty leorder ' )

Lin e_T y pe =

Lin e_Color Lin e_T y pe (Lin e ) sty le .


.
(a ) Lin e_T y p e Lin e_Color
.
(b ) Lin e_T y p e Lin e_Color
.
......................... ......................

, . ,
plot .m ty pe lin e
. default Lin e_Color , Lin e_T y p e
.

s et (0,'Defau ltA x esColor or der ' ,[0 0 0],'Defau ltA x esLin eSty leOr der ' ,' - |- .|- - |:' )

, [ 3- 18]
[ 3 - 19] figu r e .

s et .m Root Object
pr operty n am e/ pr op erty v alu e . Root Obj ect
Lev el Object . , m atlab
sty le . , s t a rtu p .m
m atlab
sty le .
! con tour .m
sty le . cont our .m
sty le .

- 13 0 -
M A T LA B

[ 3- 19] style default

, (r an g e )
, .
, .
,
a x i s .m . ,
.
, A x e s object , property n am e x lim , y lim , z lim
. ax i s .m .

(sy n tax ) : ax i s .m
ax i s ( [x m in x m ax y m in y m ax z m in z m ax ] )
(r an g e ) .
2 zm in zm ax .

t =- 5 :1/ 100:5 ;
y =1./ ((t - 0.3 ).^2+0.01)+1./ ((t - 0.9 ).^2+0.04 )- 6 ; %y h um p s fu n ction .
plot (t ,y )

, [ 3- 20] .

- 13 1 -
M A T LA B

[ 3- 20] ax is .m

, t [0 ] .
.

ax is ([0 inf - in f inf])

[ 3 - 21] t [0 ] .

A x es Object pr op erty n am e/ property v alu e t [0 ]


?
.

s et (g ca ,'x lim ' ,[0 inf],' y lim ' ,[- inf in f])

[ 3 - 21] .

- 13 2 -
M A T LA B

[ 3 - 21] 0 t 2 .
, 0 t 2 0.4 tick .
.

A x es Obj ect
pr op erty n am e pr op erty v alu e
x t ic k , y ti c k , z t ic k T ick m ark v ector

set (g ca ,'x tick ' ,[0:0.4 :2 2.5 3 3.5 4 4.5 5])

[ 3 - 22] .

, t ic k .

- 133 -
M A T LA B

[ 3- 22] T ick

, , t ticklab el( , 0, 0.4, 0.8 )


.

A x es Object
pr op erty n am e pr operty v alu e
x ticklab el, y ticklab el, zticklab el T ick m ark (strin g )

x (y ,z )ticklab el T ick m ark .


tick .
[ 3 - 22] t tick 12 .

t_lab el=str 2m at ('I ' ,'II ' ,' III ' ,'IV ' ,'V ' ,'V I ' ,'VII ' ,'V III ' ,'IX ' ,'X ' ,'XI ' ,'XII ' )
s et (g ca ,'x ticklab el ' ,t_lab el)

[ 3 - 23] x t i c k l ab e l .

- 13 4 -
M A T LA B

[ 3- 23] xticklabel

H igh _level fu n ction .

- 135 -

You might also like