Professional Documents
Culture Documents
MATLAB
7.1
7.1.1
1 plot
plot
current axes ColorOrder property
plot axes LineStyleOrder
property
plot(X,Y) X,Y X=[x(i)]
Y=[y(i)] plot(X,Y)(x(i)y(i)) XY
XY X = [X(i)]
Y = [Y(i)] X(i),Y(i) plot(X,Y) plot(X(i),Y(i))
XY
plot(X1,Y1,X2,Y2,) Xi Yi plot(X1,Y1,X2,Y2,)
Xi Yi Xi Yi
plot(X1,Y1,LineSpec1,X2,Y2,LineSpec2 )
Xi,Yi,LineSpeci LineSpeci
plot
228
plot(X1,Y1,LineSpec1,X2,Y2,X3,Y3,LineSpec3)
plot(,'PropertyName',PropertyValue,) plot line
h = plot() line
LineSpec
Maltab
1
7-1
-.
3
7-2
Rred
M(magenta)
G(green)
y(yellow)
b(blue)
k(black)
c(cyan)
w(white)
4
7-3
o()
>
<
LineSepc
plot(x,y,'-.or')
x y-.xyo
plot plot
plot(x,y,d)
7-1
229
MATLAB6.0
>>t = 0:pi/20:2*pi;
>>plot(t,t.*cos(t),'-.r*')
>>hold on
>>plot(exp(t/100).*sin(t-pi/2),'--mo')
>>plot(sin(t-pi),':bs')
>>hold off
7-1
7-2
>>plot(t,sin(2*t),'-mo', 'LineWidth',2,'MarkerEdgeColor','k',
'MarkerFaceColor',[.49 1 .63],'MarkerSize',12)
7-2
7-1
7-2
2 fplot
limits y=fx x
y x y(i)=f(x(i)) x
y y fxfx
[f1(x),f2(x),f3(x)] x=[x1;x2;x3] fx
f1(x1) f2(x1) f3(x1)
f1(x2) f2(x2) f3(x2)
f1(x3) f2(x3) f3(x3)
function m- x
eval sin(x)*exp(2*x)[sin(x),cos(x)]hump(x)
fplot('function',limits) limits function
limits x-[xmin xmax] x y
[xmin xmax ymin ymax]
fplot('function',limits,LineSpec) LineSpec function
fplot('function',limits,tol) tol function
2e-3
fplot('function',limits,tol,LineSpec) tol
LineSpec function
fplot('function',limits,n) n>=1 n+1 limits
n (xmax-xmin)/n
230
7-3
>>fplot('tanh',[-2 2])
7-3
>>subplot(2,2,1);fplot('humps',[0 1])
>>subplot(2,2,2);fplot('abs(exp(-j*x*(0:9))*ones(10,1))',[0 2*pi])
>>subplot(2,1,2);fplot('[tan(x),sin(x),cos(x)]',2*pi*[-1 1 -1 1])
7-3
7-4
3 loglog
loglog(Y) y y y
y
loglog(Y) loglog(real(Y),imag(Y)) loglog
Y
loglog(X1,Y1,X2,Y2) Xn Yn Xn Yn
loglog
loglog(X1,Y1,LineSpec1,X2,Y2,LineSpeec2 ) Xn,Yn,
LineSpecn LineSpecn
loglog(X1,Y1,X2,Y2,LineSpec2,X3,Y3)
loglog(,'PropertyName',PropertyValue,) loglog
231
MATLAB6.0
h = loglog() line
7-4
>>x = logspace(-1,2);
>>loglog(x,10*exp(x),'-s')
>>grid on
7-5
4 semilogx
x semilogx
ColorOrder LineStyleOrder
semilogx(Y)
% x 10 y
y y y
y semilogx(Y) semilogx(real(Y),imag(Y))
semilogx Y
semilogx(X1,Y1,X2,Y2)
% Xn Yn xn yn
semilogx(X1,Y1,LineSpec1X2,Y2,LineSpec2, )
%
Xn,Yn,LineSpecn LineSpecn
semilogx(X1,Y1,X2,Y2,LineSpec2,X3,Y3)
semilogx(,'PropertyName',PropertyValue,) % semilogx
h = semilogx() % line
7-5
>>x = 0:.1:10;
>>semilogx(x,cos(10.^x))
7-6
5 semilogy
semilogx
6 fill
fill(X,Y,C) x y
232
7-6
c c c
c x y c c x y
fill(X,Y,ColorSpec) ColorSpec x y
fill(X1,Y1,C1,X2,Y2,C2,)
fill(,'PropertyName',PropertyValue) patch
1. x y
fill fill x
y
2. ColorSpec
fill flat-shadedpatch FaceColor
RGB
3. c fill Clim c
c
4. c fill c xy
FaceColor 'flat'xy
n Cdata n x y
5. c fill
FaceColor interp
Cdata c
fill
7-6
>>t = (1/16:1/8:1)'*2*pi;
>>x = exp(t).*sin(t);
>>y = t.*cos(t);
>>fill(x,y,'k')
>>grid on
7-7
7-7
7 zoom
zoom on
matlab
Shift
233
MATLAB6.0
zoom off
zoom out
zoom reset
zoom out
reset
zoom on off
zoom xon x
zoom yon y
zoom(factor) factor
factor>1 factor 0<factor1
1/factor
zoom(fig, option) fig
option onoffxonyonresetfactor
8 meshgrid
z = f(x,y) x-y X Y
u = f(x,y,z) X,Y Z
a[X,Y] = meshgrid(x,y)
b[X,Y] = meshgrid(x)
c[X,Y,Z] = meshgrid(x,y,z)
a x x-y x
y x-y y X x-y
Y x-y
X_2d =
0.7000
0.7000
0.7000
Y_2d =
-2
-2
3
3
1
1
X_3d(:,:,1) =
0.7000
234
1.1000
1.1000
1.1000
1.1000
7
0.7000
0.7000
X_3d(:,:,2) =
0.7000
0.7000
0.7000
X_3d(:,:,3) =
0.7000
0.7000
0.7000
Y_3d(:,:,1) =
-2
-2
3
3
1
1
Y_3d(:,:,2) =
-2
-2
3
3
1
1
Y_3d(:,:,3) =
-2
-2
3
3
1
1
Z_3d(:,:,1) =
2
2
2
2
2
2
Z_3d(:,:,2) =
5
5
5
5
5
5
Z_3d(:,:,3) =
3
3
3
3
3
3
7.1.2
1.1000
1.1000
1.1000
1.1000
1.1000
1.1000
1.1000
1.1000
1 polar
rho=f()
7-8
>>t = 0:.01:2*pi;
>>polar(t,sin(3*t).*cos(2*t),'--r')
7-8
2 bar
7-8
bar(Y) y
1 lengthy y bar y
1 sizey1
235
MATLAB6.0
bar(x,Y) x y x y
bar
bar(,width) 0.8
x width
1
bar(,'style') groupstackgroup
stack y
bar(,LineSpec) LineSpec
[xb,yb] = bar() plot patch xbyb
plot
h = bar() patch
7-9
x = -2.9:0.2:2.9;
bar(x,exp(x.*sin(x)))
colormap gray
W idth = 1.5
7
6
5
7-9
7-10
4
3
subplot(2,2,4)
bar(Y,1.5)
title 'Width = 1.5'
7-10
3 barh
236
2
1
0
0
7-9
10
15
20
25
30
35
7-10
barh(Y) y 1 length(y)
y bar y 1 size(y,1)
barh(x,Y) x y x
y barh
barh(,width) 0.8
x width
1
barh(,'style') groupstack
group
stack
y
barh(,LineSpec) LineSpec
[xb,yb] = barh() plot patch xbyb
plot
h = barh() patch
7-11
>>X = 1:.5:5;
>>Y = exp(X).*sin(X);
>>barh(Y,'stack')
7-11
4 compass
7-11
compass(X,Y) x y n n
[X(i),Y(i)]
compass(Z) z n n
[real(Z),imag(Z)].
compass(,LineSpec) LineSpec
h = compass() line h
7-12
Z = magic(20).*randn(20);
compass(Z)
7-12
5 comet
7-12
comet
EraseMode none
comet(y) y
comet(x,y) x y
comet(x,y,p) p*length(y)
p 0.1
7-13
>>t = 0:.01:2*pi;
>>x = exp(sin(2*t)).*(cos(t).^2/3);
>>y = t.*(sin(t).^2);
>>comet(x,y);
7-13
7-13
237
MATLAB6.0
(EraseMode){normal}|none|xor|background
7-4
Normal
()
none
xor
Background
(xor)
none
6 errorbar
errorbar(Y,E) y y
E(i) y 2*E(i)
errorbar(X,Y,E) X,Y,E 2*E(i)
(X(i),Y(i)) E(ij)
(X(i,j),Y(i,j))
errorbar(X,Y,L,U) XYLU (X(i),Y(i))
L(i) U(i)
(X(i,j),Y(i.j)) L(i,j), U(i,j)
errorbar(,LineSpec) LineSpec
h = errorbar() h
7-14
>>X = 0:pi/10:pi;
>>Y = exp(X).*sin(X);
>>E = std(Y)*ones(size(X));
>>errorbar(X,Y,E)
7-14
7 feather
7-14
feather(U,V) u v u
x v y
feather(Z) z feather(real(Z),imag(Z))
238
feather(,LineSpec) LineSpec
7-15
>>th = (-90:10:90)*pi/180;
>>r = 4*ones(size(th));
>>[u,v] = pol2cart(th,r);
>>feather(u,v);
7-15
8 hist
7-15
y
y
x y y
y
y 0
patch patch
n = hist(Y) y 10
y y
n = hist(Y,x) x y mm=length(x) x
n = hist(Y,nbins) nbins
[n,xout] = hist() n xout
bar(xout,n)
7-16
>>x = -5:0.1:5;
>>y = randn(1000,1);
>>hist(y,x)
7-16
9 histc
7-16
n = histc(x,edges) x edges
n
edges edges(k)>=x(i)>=edges(k+1) n(k) 1X
edges edges -inf
inf x NaN x x
n = histc(x,edges,dim) dim
[n,bin] = histc() n bin x n(k) = sum(bin
== k)bin
10 rose
239
MATLAB6.0
rose(theta) theta 20
theta
rose(theta,x) xlength(x)
x 5
rosetheta 5 x
rose(theta,nbins) [0,2*pi] nbins 20
[tout,rout] = rose() tout rout polar(tout,rout)
7-17
>>theta = 3*pi*randn(1,30);
>>rose(theta)
7-17
11 stairs
7-17
stairs(Y) y y x 1
m=length(y) y y x 1
y m
stairs(X,Y) x y x y x
y m=lengthx
stairs(,LineSpec) LineSpec
[xb,yb] = stairs(Y) plot y
xb yb
[xb,yb] = stairs(X,Y)
plot xy xb yb
7-18
>>x = 0:.25:10;
>>stairs(x,exp(sin(x.^2)))
7-18
12 stem
7-18
x
y
stem(Y) y x y
y
stem(X,Y) x y x y
x y m=lengthx
stem(,'fill')
240
stem(,LineSpec) LineSpec
h = stem() line
7-19
>>x = linspace(0,2,10);
>>stem(exp(-x.^2),'fill','-.')
7-19
7-19
13 stem3
xy
stem3(Z) z xy z x y
stem3 x z
y stem3 y z
stem3(X,Y,Z) x y z xyz
stem3(,'fill')
stem3(,LineSpec)
h = stem3() line
7-20
[X,Y,Z] = peaks(20);
stem3(X,Y,Z,r*')
7-20
7-20
14 pie
pie(X) x x X
X(i) X(i)/sum(X)
sum(X)=1 x sum(X)<1
pie(X,explode) explode x
explode
explode x
h = pie() patch text h
7-21
>>x = [1 3 0.5 2.5 2];
>>explode = [0 1 0 0 0];
>>pie(x,explode)
7-21
7.1.3
7-21
1 grid
XgridYgrid
241
MATLAB6.0
Zgrid
grid on
grid off
grid
grid(axes_handle,on|off) axes_handle
2 gtext
gtext('string')
string
h = gtext('string') string text
h
3 legend
patch surface
Matlab
legend('string1','string2',) string
legend(h,'string1','string2',) string h
legend(string_matrix) string_matrix
legend(h,string_matrix) string_matrix
h
legend(axes_handle,) axes_handle
legend('off') axes-handle
legend(axes_handle,'off') axes_handle
legend_handle = legend
legend
legend(legend_handle) legend_handle
legend(,pos) pos 7-5
7-5
242
Pos
pos=-1
Pos
pos=2
pos=0
pos=3
Pos=1
pos=4
h = legend()
[legend_handle,object_handles] = legend()
line
text
7-22
>>x = -pi:pi/20:pi;
>>plot(x,(cos(x)).^2,'rd',x,asin(x),'-.b')
>>h = legend('cos2x','asin',2);
7-22
7-22
4 title
axes axes
title('string') string
title(fname) fname
h = title() text
5 text
text text text
text(x,y,'string')(x,y) string
text(x,y,z,'string') (x,y,z) string
text(x,y,z,string.'PropertyName',PropertyValue) string
7-6
7-6
Editing
Interpretation
TeX
String
Extent
( TeX )
HorizontalAlignment
Position
Rotation
onoff
off
texnone
tex
)
left
[x,y,z]
[]
243
MATLAB6.0
Units
VerticalAlignment
pixels ( )
normalized ( 1
)inches()centimeters()points
()data
data
top ()cap(
)middle()
baseline()bottom(
)
middle
FontAngle
FontName
FontSize
FontUnits
FontSize
FontWeight
normal()italic()
oblique()
normal
FixedWidth
Helvetica
10 points
points (1 =1/72 )
normalized(
)inches ()
Centimeters()Pixels()
points
light()normal()
demi()Bold()
normal
Clipping
onoff
on
off
off
EraseMode
normalnone xor
normal
SelectionHighlight
Visible
Color
HandleVisibility
HitTest
CurrentObject
onoff
on
onoff
on
ColorSpec
oncallbackoff
on
onoff
on
Children
Parent
Seleted
244
axes
[]
axes
onoff
off
background
Tag
Type
text
UserData
[]
BusyAction
ButtonDownFcn
CreateFcn
DeleteFcn
Interruptible
UIContextMenu
cancelqueue
queue
' '
' '
' '
onoff
on
h = text()
7-23
>>plot(0:pi/20:2*pi,sin(0:pi/20:2*pi))
>>text(pi,0,Zeros Point)
>>grid on
7-23
6 xlabelylabel
xy
7-23
xlabel('string') ylabel(string)
xy xlabel ylabel
xlabel(fname)ylabel(fname) fname x
y
xlabel( ,'PropertyName',PropertyValue, ) ylabel( ,PropertyName,
PropertyValue)
xlabel ylabel text
h = xlabel()h = ylabel() text
7.2
7.2.1
1 comet3
245
MATLAB6.0
EraseMode none
comet3(z) z
comet3(x,y,z) xyz
comet3(x,y,z,p) p*length
y
7-24
>>t = -20*pi:pi/50:20*pi;
>>comet3((cos(2*t).^2).*sin(t),(sin(2*t).^2).*cos(t),t);
7-24
7-24
2 fill3
Gouraud
fill3(X,Y,Z,C) xy z xy z fill3
n n fill3
c c
c c x
y c c x y
fill3(X,Y,Z,ColorSpec) ColorSpec xy z
fill3(X1,Y1,Z1,C1,X2,Y2,Z2,C2,)
fill3(,'PropertyName',PropertyValue) patch
h = fill3() patch patch
2 XY Z fill3
3 ColorSpec fill3 flat-shaded
patch FaceColor RGB
4 C fill3 Clim C
5 C fill3 flat-shaded
FaceColor flat c
CData
6 C fill3
FaceColor interp fill3
C
246
Cdata
7 C fill3 C
6
7-25
>>X = 10*rand(4);Y=10*rand(4);Z=10*rand(4);
>>C = rand(4);
>>fill3(X,Y,Z,C)
7-25
7.2.2
7-25
1 contour
contour(z) z
v Matlab
contour(x,y,z) (x,y) z=0 z
contour(z,n) n
contour(x,y,z,n) n
contour(z,v) v
contour(x,y,z,v)
[c,h] = contour() contourc c
h clabel
userdata
contour(,linespec)
7-26
>>contour(peaks(40))
7-26
7-26
2 clabel
h
+
clabel(C,h)
clabel(C,h,v) v h
clabel(C,h,'manual')
clabel(C) contour c
247
MATLAB6.0
clabel(C,v) v
clabel(C,'manual')
7-27
>>[x,y] = meshgrid(-2:.2:2);
>>z = x.*y.*exp(-x.^2-y.^2);
>>[C,h] = contour(x,y,z);
>>clabel(C,h);
7-27
7-27
3 contourc
c contour
contour3 contourf z
z
C = contourc(Z) z z 2*2
z
C = contourc(Z,n) z n
C = contourc(Z,v) z v v
a
contourc(Z,[a,a])
C = contourc(x,y,Z) z xy
C = contourc(x,y,Z,n) Z x y n
C = contourc(x,y,Z,v) Z x y v
4 contour3
contour3(Z) z z
xy z 2*2
[mn]=sizez x [1n]y [1m]
contour3(Z,n) z n
contour3(Z,v) v v
h contour3(Z,[h,h])
contour3(X,Y,Z)contour3(X,Y,Z,n)contour3(X,Y,Z,v) X Y x- y X X(1,:) x- Y Y(:,1)
y- X Y
surf X Y contour3
X Y
contour3(,LineSpec) LineSpec
[C,h] = contour3() contourcC
hLineSpeccontour3
patchcolormapcaxis
248
line
7-28
>>[X,Y] = meshgrid([-2:.25:2]);
>>Z = X.*exp(-X.^2-Y.^2);
>>contour3(X,Y,Z,30)
7-28
5 contourf
7-28
contourf(Z) z z Z 2*2
contourf(Z,n) z n
contourf(Z,v) z v
contourf(X,Y,Z)contourf(X,Y,Z,n)contourf(X,Y,Z,v) z
X Y x- y- X Y Z
X Y contour3
X Y
[C,h,CF] = contourf() contourc
CC clabel patch h
CF
7-29
>>contourf(peaks(30),20);
>>colormap gray
7-29
6 pie3
7-29
pie3(X) x X
pie3(X,explode) x explode
x explode x
pie3 x x
1 1 x
7-30
>>x = [1 3 0.5 2.5 2]
>>ex = [0 1 0 0 0]
>>pie3(x,ex)
7-30
7-30
249
MATLAB6.0
7.2.3
1 mesh
XY Z C
view3 surface
hidden
shading
mesh(X,Y,Z) c
1 X Y lengthX=nlengthY=m[mn]=size
Z (X(j),Y(I),Z(I,j))
X z Y z
2 X Y (X(I,j),Y(I,j),Z(I,j))
mesh(,C) c Matlab c
mesh(,PropertyName,PropertyValue, ) PropertyName
PropertyValue,
h = mesh() surface
1 XY z XLimModeYLimMode ZLimMode
aXis
2 c Clim ClimMode caxis
3 z Matlab
caxis auto
Matlab
7-31
>>[X,Y] = meshgrid(-3:.125:3);
>>Z = peaks(X,Y);
>>mesh(X,Y,Z);
7-31
7-31
2 surf
surf(Z) z [mn] = sizeZ
X = 1nY = 1m z
z
250
surf(X,Y,Z) z X Y X
Y X Y lengthX=nlengthY=m
[m,n]=sizeZX(I),Y(j),Z(I,j)
surf(X,Y,Z,C) c Matlab c
surf(,PropertyName,PropertyValue) PropertyName
PropertyValue
h = surf() surface h
1 Ij
a<=I<=b,c<=j<=d XYZ
C
2
A(I-1,j)
|
B(I,j-1) ---- C(I,j) ---- D(I,j+1)
|
E(I+1,j)
[X(,Y(,Z)
3
X Y
facted flatc(I,j)
A(I,j)----------- B (I,j+1)
|
C(I,j)
|
C(I+1,j) --------- D(I+1,j)
C XY Z
C XYZ 1
5 surf view3
6 XYZ XlimModeYlimMode ZlimMode
axis
7 C Clim
ClimMode caxis
7-32
>>[X,Y,Z] = peaks(30);
>>surf(X,Y,Z)
>>colormap hsv
7-32
7-32
251
MATLAB6.0
3 surfc
surfc(Z)surfc(X,Y,Z) surfc(X,Y,Z,C)
surfc(,PropertyName,PropertyValue)
surfc() h = surfc()
surf
7-33
>>[X,Y,Z] = peaks(30);
>>surfc(X,Y,Z)
>>colormap hsv
7-33
7-33
4 surfl
graycopperbonepink XYZ
surfl(X,Y,Z)
surfl(Z) z
surfl(X,Y,Z) XYZ
7-34
7-34
252
5 waterfall
waterfall(X,Y,Z) XY Z X Y
X Z Y Z length(X)=Z
length(Y)=Z X Y x- y-Z z-
Z
waterfall(Z) waterfall(X,Y,Z)
waterfall(Z) X=1:Z Y=1:Z Z
waterfall(,C) C
Z
h = waterfall() patch h
7-35
>>[X,Y,Z] = peaks(30);
>>waterfall(X,Y,Z)
7-35
6 cylinder
x-y-z- surf mesh
7-35
7-36
>>t = 0:pi/10:2*pi;
>>[X,Y,Z] = cylinder(2+(cos(t)).^2);
>>surf(X,Y,Z); axis square
7-36
7-36
7 sphere
sphere 20*20
sphere(n) n*n
[X,Y,Z] = sphere(n) (n+1)*(n+1)
surfXYZ mesh
253
MATLAB6.0
XYZ
7-37
>>[X,Y,Z]=sphere;
>>mesh(X,Y,Z)
>>hidden off
7-37
7.2.4
7-37
1 pcolor
c c
surf(X,Y,0,C)view([0,90])
h = pcolor() surface h
7-38
>>pcolor(magic(20))
>>colormap(gray(2))
>>axis ij;axis square
7-38
7-38
2 quiver
quiver(U,V) x =1:n y =1:m U V
[m,n]=size(U)=size(V) U V
quiver
quiver(X,Y,U,V) X Y X Y
lengthX=n lengthY=m[mn]=sizeU=sizeV
X UV Y UV
quiver(,scale) scale
scale=2 2 scale=0
quiver(,LineSpec) quiver
254
quiver(,LineSpec,'filled') LineSpec
h = quiver()
7-39
>>[z,x,y]=peaks(30);
>>[Dx,Dy]=gradient(z,0.1,0.1);
>>quiver(x,y,Dx,Dy)
7-39
7-39
3 slice
slice(X,Y,Z,V,sx,sy,sz) V=V(X,Y,Z) x-y-
z- V=V(X,Y,Z) X
X0 V=V(X0,Y,Z)
V,
sxsy sz X Y Z
V XY Z
meshgrid V
slice(,'method') methodlinear
cubicnearest
linear
cubic
nearest
h = slice() h
4 axis
axis([xmin xmax ymin ymax]) x- y-
axis([xmin xmax ymin ymax zmin zmax cmin cmax]) x-y z-
XlimYlim Zlim
255
MATLAB6.0
XLimYlim Zlim
axis auto
xy z
XlimModeYlimMode ZlimMode auto
axis auto x x-
axis auto yz y- z-
axis manual axis(axis) (hold)
on XLimMode
YLimMode ZlimMode manual
axis tight
axis fill
axis ij j-
i-
axis xy x-
y-
axis equal x-
y- z-
axis image axis equal
axis square x-y- z
axis normal
7-7
7-7
DataAspectRatioMode
PlotBoxAspectRatio
PlotBoxAspectRatioMode
Stretch-to-fill
axis equal
axis normal
axis square
axis tightequal
[1 1 1]
manual
[3 4 4]
auto
auto
[1 1 1]
[1 1 1]
Manual
Auto
axis vis3d
axis off text gtext
axis on
[mode,visibility,direction] = axis('state')
256
7-8
7-8
Mode
auto
manual
Visibility
Direction
onoff
xyij
7-40
>>x = 0:.025:pi/2;
>>plot(x,exp(x).*sin(2*x),'-m<')
>>axis([0 pi/2 0 5])
7-40
5 hidden
7-40
hidden on
FaceColor
hidden off
hidden on off
7-41
>>mesh(peaks)
>>hidden off
7-41
7-41
6 shading
EdgeColor FaceColor shading
shading flat
shading faceted
shading interp
7-42
>>sphere(16)
>>axis square
>>shading flat
>>title('Flat Shading')
7-42
7 caxis
caxis
7-42
257
MATLAB6.0
CData
CDataMapping surfacepatches images
CDataCDataMapping surfaceimages
patches Clim ClimMode
caxis([cmin cmax]) cmin
cmax cmin cmax cmin cmax
caxis auto
Inf-Inf
NaN
caxis manualcaxis(caxis) hold
on
v = caxis v=[cmin cmax]
caxis(axes_handle,) axis_handle
(Cdata)(CdataMapping)
surfacepatch image
cmin
cmax
cmin cmax
c m
index
index = fix((C-min)/(cmax-cmin)*m)+1
7-43
>>[X,Y,Z] = sphere;
>>C = Z;surf(X,Y,Z,C)
>>caxis([-1 3])
7-43
7-43
8 view
azimuthelevation
view(az,el)view([az,el]) az
el z- xy
y- z-
az
z-
xy el
view([x,y,z]) x,y,z
258
view(2) az=0el=90 z-
view(3) az=-37.5el=30
view(T) T T 4*4 viewmtx
[az,el] = view az el
T = view 4*4 T
7-44
>>peaks;
>>az = 0;el = 90;
>>view(az, el)
7-44
7-44
9 viewmtx
4*4
T = viewmtx(az,el) az el
T = viewmtx(az,el,phi) phi
7-9
Phi
0
10
25
60
view(T) 4*4
(x,y,z,w) w 1 x y-(x/w,y/w,z/w,1)
1[x,y,z,1][x,y,z]
T = viewmtx(az,el,phi,xc) xc
xc xc
xc=[xc,yc,zc][01]
xc=[0 0 0]
10 surfnorm
surf
surfnorm(Z)surfnorm(X,Y,Z) Z
X Y x y
[Nx,Ny,Nz] = surform()
Nx,Ny Nz
7-45
>>[x,y,z] = cylinder(1:10);
>>surfnorm(y,x,z)
259
MATLAB6.0
>>axis([-12 12 -12 12 -0.1 1])
7-45
7-45
7.3
7.3.1
1 figure
figure
figure('PropertyName',PropertyValue,) PropertyName
PropertyValue
figure(h) 1. h figure(h) h
2. h
h h
h = figure() h
7-10
Position
Units
Position
260
[left,bottom,
width,height]
inches()
centimeters()
normalized( 1)
points()
pixels()
characters()
pixels
Color
Menubar
Name
NumberTitle
Resize
SelectionHighlight
Visible
WindowStyle
Figure No. n, n
ColorSpec
( colordef)
nonefigure
figure
onoff
on
onoff
on
onoff
on
onoff
on
normal
modal
normal
Colormap
Dithermap
DithermapMode
FixedColors
MinColormap
ShareColors
MATLAB
m*3 RGB
jet
m*3 RGB
automanual
manual
m*3 RGB
64
onoff
on
m*1 [0 1]
64*1
onoff
on
onoff
off
painterszbufferOpenGL
guide
Alphamap
BackingStore
DoubleBuffer
Renderer
Children
FileName
Parent
Selected
Tag
0
onoff
on
261
MATLAB6.0
Type
UserData
RendererMode
' '
'figure'
[]
automanual
auto
CurrentAxes
CurrentCharacter
CurrentOject
CurrentPoint
SelectionType
BusyAction
ButtonDownFcn
CloseRequestFcn
CreateFcn
DeleteFcn
Interruptible
KeyPressFcn
ResizeFcn
UIContextMenu
WindowButtonDownFcn
WindowButtonMotionFcn
WindowButtonUpFcn
[x-coord
y-coord]
normalextendedaltopen
cancelqueue
queue
onoff
on
oncallbackoff
on
onoff
on
' '
closereq
' '
' '
onoff
on
' '
' '
UIContrextmenu
' '
' '
' '
IntegerHandle
HandleVisiblity
HitTest
262
NextPlot
CurrentObject)
replacechildrenaddreplace
add
Pointer
PointerShapeCData
PointerShapeHotSpot
crosshairarrowtoprwatchtoplbotl
botrcirclecrossfleurleftrighttopfullcrosshair
bottom ibeamcustom
arrow
16*16
'custom'
[rowcolumn]
[1 1]
7-46
>>scrsz = get(0,'ScreenSize');
>>figure('Position',[1 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2])
2 line
line line
line
1line(X,Y,Z)
Matlab ColorOrder LineStyle
2 line
line(XData,x,YData,y,ZData,z)
Matlab colordef
line
line(X,Y) x y x y
xy
line(X,Y,Z) xyz
line(X,Y,Z,'PropertyName',PropertyValue,) xyz
PropertyName PropertyValue
LineStyle Marker plot
line('PropertyName',PropertyValue,)
line
h = line()
7-11
Xdata
x-
Ydata
y-
[0 1]
[0 1]
263
MATLAB6.0
Zdata
z-
[0 1]
LineStyle
LineWidth
Marker
MarkerFaceColor
MarkerSize
MarkerEdgeColor
----. none
-
0.5
13
none
autonone ColorSpec
auto
Clipping
EraseMode
SelectionHighlight
Visible
Color
HandleVisibility
HitTest
Children
Parent
Selected
Tag
Type
UserData
onoff
on
normalnone
xorbackground
normal
onoff
on
onoff
on
ColorSpec
onoffcallback
on
onoff
on
onoff
on
'line'
BusyAction
ButtonDownFcn
CreateFcn
DeleteFcn
Interruptible
UIContextMenu
7-47
264
cancelqueue
queue
' '
' '
' '
onoff
on
UIContextMenu
>>t = 0:pi/20:2*pi;
>>hline1 = plot(t,exp(t).*sin(t),'k');
>>hline2 = line(t+.06,exp(t).*sin(t),'LineWidth',4,'Color',[.8 .8 .8]);
>>set(gca,'Children',[hline1 hline2])
7-46
7-46 line
7-48
>>line(rand(4,2),rand(4,2),rand(4,1))
>>line(rand(1,4),rand(1,4),rand(1,4))
>>line(rand(4,1),rand(4,1),rand(4,1))
>>line(rand(2,4),rand(2,4),rand(1,4))
>>line(rand(4,2),rand(4,2),rand(4,1))
7-47
3 patch
7-47
patch(X,Y,C) X,Y
X,Y xy
x y
c ColorSpec
c
RGB
patch(X,Y,Z,C)
patch(FV) FV FV verticesfaces
facevertecdata Vertices Faces
FaceVertexCData
patch(,C,'PropertyName',PropertyValue) (X,Y)(X,Y,Z)
PropertyName PropertyValue
patch('PropertyName',PropertyValue) PropertyName
265
MATLAB6.0
PropertyValue
FaceColor
EdgeColor Faces Vertices
x-y- z-
handle = patch() patch
patch fill area
NextPlot
4 surface
AI
j I x- j y- z-
surface(Z) z z
surface(Z,C) c z
surface(X,Y,Z) xyz c=z
surface(X,Y,Z,C) xyz c
Surface(x,y,Z) x y [m,n]=size(z) length(x)=n
length(y)=m(x(j),y(i),z(I,j))
Surface(x,y,Z,C) c
surface('PropertyName',PropertyValue,) PropertyName
PropertyValue
h = surface()
5 image
c
RGB Image
1 newplot
Ydir rervse
View [0 90]
2 newplot
/
image(C) C C
266
image(x,y,C) (x,y) C xy 2
x y image(C)
image(x,y,C,'PropertyName',PropertyValue,) /
newplot
image('PropertyName',PropertyValue,)
/
handle = image()
7-49
>>load clown
>>image(X,'CDataMapping','scaled')
>>colormap(map)
7-48
7-48
6 uicontrol
get(edit_handle,String)
string
Stacking order
string
Min Max Value
Value MATLAB
Done
Callback
SelectionType normal open
267
MATLAB6.0
string
on off
7-12 uicontrol
7-12
ColorSpec
ColorSpec
[0 0 0]
onoff
on
BackgroundColor
Cdata
ForegroundColor
SelectionHighlight
String
Visible
onoff
on
Children
268
Enable
Parent
Selected
SliderStep
Style
Tag
TooltipString
Type
UserData
Position
Units
position
oninactiveoff
on
onoff
off
[0.001 0.1]
pushbuttonedittogglebutton
slidertextradiobuttonpopupmenu
listboxframe
pushbutton
uicontrol
[20 20 60 20]
pixelsinchescharacter
normalizedpointscentimeters
pixels
FontAngle
FontName
FontSize
FontUnits
FontWeight
HorizontalAlignment
String
normalitalicoblique
normal
pixelsnormalized inches
centimeterspoints
points
lightnormaldemibold
normal
leftcenterleft
BusyAction
ButtonDownFcn
Callback
CreateFcn
DeleteFcn
Interruptible
ListboxTop
Max
UIContextMenu
cancelqueue
queue
onoff
on
269
MATLAB6.0
Min
Value
HandleVisibility
GUIs
HitTest
oncallbackoff
on
onoff
on
7 uimenu
handle = uimenu('PropertyName',PropertyValue,)
PropertyName PropertyValue
handle
uimenu('PropertyName',PropertyValue,)
handle = uimenu(parent,'PropertyName',PropertyValue,)
parent parent
handle
uimenu(parent,'PropertyName',PropertyValue,)
7-13 uimenu
7-13
Checked
ForegroundColor
Label
Separator
SelectionHighlight
Visible
Acceleratro
Children
Enable
Parent
270
onoff
off
ColorSpec
[0 0 0]
onoff
off
onoff
on
onoff
on
onoff
on
Tag
Type
UserData
Position
read-only
uimenu
[1]
BusyAction
ButtoDownFcn
Callback
CreateFcn
DeleteFcn
Interruptible
cancelqueue
queue
onoff
on
HandleVisibility
HitTest
7.3.2
oncallbackoff
on
onoff
on
1 axes
axes
axes('PropertyName',PropertyValue,) 'PropertyName'
PropertyValue
axes(h) h h
Children property
CurrentAxes h imagelinepatchsurface
text
h = axes()
2 cla
callback HandleVisibility
cla HandleVisibility on
cla HandleVisibility
on
cla reset
Position Units
3 gca
h=gca
271
MATLAB6.0
get(gcf,CurrentAxes)
plottextsurf
7.3.3
1 gco
uimenus
CurrentObject
CreateFcn DeleteFcn
Callback
h = gco h
h = gco(figure_handle) figure_handle
2 get
get(h) h
get(h,'PropertyName') h PropertyName
a = get(0,'Factory') a
a = get(0,'FactoryObjectTypePropertyName')
FactoryObjectTypePropertyName
Factory Figure ( Color)
FactoryFigureColor
a = get(h,'Default') h a
a = get(h,'DefaultObjectTypePropertyName')
DefaultObjectTypePropertyName
Default FigureColor
DefaultFigureColor
272
7-50
LineWidth
get(0,'DefaultLineLineWidth')
3 set
set(H,'PropertyName',PropertyValue,) 'PropertyValue' H
'PropertyName'H
set
set(H,a) H a
set(H,pn,pv) H pn
pv
set(H,pn,<m-by-n cell array>) m n
m=length(H)n pn
a= set(h) h a
ah
a= set(0,'Factory')
a
a
a= set(0,'FactoryObjectTypePropertyName')0
ObjectTypePropertyName
Factory axes position
a= set(h,'Default') h h
a= set(h,'DefaultObjectTypePropertyName') h
ObjectTypePropertyName
Factory axes position
4 reset
reset(h) h
h figure PositionUnitsPaperPosition PaperUnits
h axes Position Units
7-51
reset(gca) %
reset(gcf) %
5 delete
(Current
273
MATLAB6.0
delete(h) h
delete('filename') filename
delete(D:\MATLABR12\work\*.m) % .m
6 findobj
h = findobj
h = findobj('PropertyName',PropertyValue,) PropertyName
PropertyValue PN PV
findobj
h = findobj(objhandles,) objhandles
h = findobj(objhandles,'flat','PropertyName',PropertyValue, )
objhandles
7.3.4
subplot
subplot(m,n,p) m*n p
p
p
subplot(h) h
subplot('Position',[left bottom width height]) 4
h = subplot() h
2 hold
ishold
NextPlot
hold on
NextPlot add
274
3 gcf
h = gcf plottitle surf
get(0,'CurrentFigure')
4 clf
callback HandleVisibility
clf HandleVisibility on
clf
HandleVisibility on
clf reset
PositionUnitsPaperPositionPaperUnits
5 close
close
close(h) h h close
m-
newplot
1
2
3
275
MATLAB6.0
5newplot NextPlot
newplot
h = newplot h
7.4
7.4.1
colormap
m*3 0 1
RGB k k
map(k,:)=[r(k) g(k) b(k)]
colormap(map) map map [0 1]
color m- m-
colormap(hsv(64)) 64 hsv
colormap(hsv) hsv MATLAB
7-14
7-14
Cool
Bone
Flag
Jet
Copper
Hsv
Hot
Gray
Pink
Prim
Lines
White
Colorcube
Autumn
Spring
Summer
Winter
Hsv
7-52
colormap('default')
cmap = colormap
2 bone
bone(m) m*3 bone
bone
276
3 cool
cool(m) m*3 cool
cool
4 copper
copperm m*3 copper
copper
5 flag
flagm m*3 flag m
flag
6 gray
graym m*3
gray
7 hot
hotm m*3 hot
hot
8 hsv
- hsv
jet
10 pink
pinkm m*3 pink
pink
11 prism
hsv prism
prism hsv
277
MATLAB6.0
7.4.2
prismm m*3
prism
1 brighten
brighten(beta) 0<beta<1-1<beta<0
brighten(h,beta) h
newmap = brighten(beta)
newmap
newmap = brighten(cmap,beta) cmap
newmap
2 colorbar
colorbar
colorbar('vert')
colorbar('horiz')
colorbar(h) h
h = colorbar() h
colorbar(,'peer',axes_handle) axes-handle
3 contrast
cmap = contrast(X) cmap
4 rgbplot
rgbplot(cmap) m*3 cmap
278
5 diffuse
R = diffuse(Nx,Ny,Nz,S) [Nx,Ny,Nz]S
S [Theta,Phi]
Lambert R = cos(PST) PST
6 specular
R = specular(Nx,Ny,Nz,S,V,spread) [Nx,Ny,Nz]
S V [x,y,z]
[Theta,Phi](S+V)/2
spread
7 surfl
surfl() surf()
surfl(Z)surfl(X,Y,Z)surfl(Z,S)surfl(X,Y,Z,S)surfl(X,Y,Z,S,K)
S[Sx,Sy,Sz]
S [AZ,EL]S
45 clahold onview(AZ,EL)surfl()hold
off (AZ,EL)
K=[ka,kd,ks,
spread]
surfl(,'light') LIGHT
surfl(,'cdata') cdata
H = surfl()
279