Professional Documents
Culture Documents
(Roger Jang)
jang@mirlab.org
http://mirlab.org/jang
MATLAB
4-1
mesh surf
meshMesh Plots
surfSurface Plots
4-1: plotxyz001.m
z = [0 2 1; 3 2 4; 4 4 4; 7 6 8];
mesh(z);
xlabel('X = column index');
% X
% Y
MATLAB
4-1
4-1 plotxyz001.m
0
4
3
2.5
2
2
1.5
Y = row index
X = column index
MATLAB
4-1
4-2 plotxyz002.m
x y
mesh
z = [0 2 1; 3 2 4; 4 4 4; 7 6 8];
mesh(z);
xlabel('X = column index');
% X
% Y
for i=1:size(z,1)
for j=1:size(z,2)
h=text(j, i, z(i,j), num2str(z(i, j)));
MATLAB
4-1
4-2 plotxyz002.m
8
7
6
4
4
4
4
2
3
0
4
2.5
2
2
Y = row index
0
1
1.5
1
X = column index
MATLAB
4-1
4-3 plotxyz011.m
meshgrid x y
Grid Points xx
yy x y
MATLAB
4-1
4-3 plotxyz011.m
x = 3:6;
y = 5:9;
% xx yy
zz = xx.*yy;
% zz
subplot(2,2,1); mesh(xx);
title('xx'); axis tight
subplot(2,2,2); mesh(yy);
title('yy'); axis tight
subplot(2,2,3); mesh(xx, yy, zz);
title('zz xx yy '); axis tight
MATLAB
4-1
4-3 plotxyz011.m
xx
yy
6
5
3
4
2
zz xx yy
40
20
8
6
MATLAB
4-1
4-4 plotxyz01.m
linspace
x2 y2
z x
x = linspace(-2, 2, 25);
% x [-2,2] 25
y = linspace(-2, 2, 25);
% y [-2,2] 25
% xx yy 2525
zz = xx.*exp(-xx.^2-yy.^2);
% zz 2525
MATLAB
4-1
4-4 plotxyz01.m
0.5
-0.5
2
1
2
1
-1
-1
-2
-2
MATLAB
4-1
4-5 plotxyz02.m
surf mesh
x = linspace(-2, 2, 25);
% x [-2,2] 25
y = linspace(-2, 2, 25);
% y [-2,2] 25
% xx yy 2525
zz = xx.*exp(-xx.^2-yy.^2);
% zz 252
MATLAB
4-1
4-5 plotxyz02.m
0.5
-0.5
2
1
2
1
-1
-1
-2
-2
MATLAB
4-1
peaks
MATLAB peaks
Local MaximaLocal
Minima
z 31 x e
2 x 2 y 12
x 3 5 x 2 y 2 1 x 12 y 2
10 x y e
e
3
5
MATLAB
4-1
MATLAB
peaks
z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2)
MATLAB
4-1
peaks
Peaks
-5
2
0
-2
y
-3
-2
-1
x
MATLAB
4-1
meshz
meshz
4-6plotxyz03.m
[x, y, z] = peaks;
meshz(x,y,z);
axis tight;
MATLAB
4-1
4-6plotxyz03.m
-5
2
0
-2
-3
-2
-1
MATLAB
4-1
waterfall
waterfall x y
4-7plotxyz04.m
[x, y, z] = peaks;
waterfall(x,y,z);
axis tight;
MATLAB
4-1
4-7plotxyz04.m
-5
2
0
-2
-3
-2
-1
MATLAB
4-1
meshc
meshc
Contours
4-8plotxyz05.m
[x, y, z] = peaks;
meshc(x, y, z);
axis tight;
MATLAB
4-1
4-8plotxyz05.m
-5
-10
2
0
-2
-3
-2
-1
MATLAB
4-1
plot3
plot3
4-9plotxyz06.m
t = linspace(0,20*pi, 501);
% 0 20*pi 501
% tsin(t),tcos(t),t
MATLAB
4-1
4-9plotxyz06.m
-5
-10
2
0
-2
-3
-2
-1
MATLAB
4-1
plot3
4-10plotxyz07.m
t = linspace(0, 10*pi, 501);
plot3(t.*sin(t), t.*cos(t), t, t.*sin(t), t.*cos(t), -t);
MATLAB
4-1
4-10plotxyz07.m
40
20
-20
-40
40
20
40
20
-20
-20
-40
-40
MATLAB
4-1
plot3
xyz
plot3
4-11plotxyz08.m
[x, y] = meshgrid(-2:0.1:2);
z = y.*exp(-x.^2-y.^2);
plot3(x, y, z);
MATLAB
4-1
4-11plotxyz08.m
0.5
-0.5
2
1
2
1
-1
-1
-2
-2
MATLAB
4-1
plot3
MATLAB
griddata
MATLAB
4-1
4-12plotxyz09.m
x = 6*rand(100,1)-3;
% x [-3, 3] 100
y = 6*rand(100,1)-3;
% y [-3, 3] 100
z = peaks(x, y);
% z peaks 100
[X, Y] = meshgrid(-3:0.1:3);
Z = griddata(x, y, z, X, Y, 'cubic');
mesh(X, Y, Z);
hold on
plot3(x, y, z, '.', 'MarkerSize', 16);
hold off
axis tight
% 100
MATLAB
4-1
4-12plotxyz09.m
6
4
2
0
-2
2
0
-2
-3
-2
-1
MATLAB
4-1
mesh, ezmesh
meshc, ezmeshc
meshz
surf, ezsurf
surfc, ezsurfc
surfl
MATLAB
4-1
plot3, ezplot3
surface
Surf
line3
Plot3
contour,
ezcontour
contour3
pcolor
MATLAB
4-1
ezmesh, ezsurf
ezmesh
ezsurf
4-13plotxyz091.m
subplot(2,2,1);
ezmesh('sin(x)/x*sin(y)/y');
subplot(2,2,2);
ezsurf('sin(x*y)/(x*y)');
subplot(2,2,3);
ezmeshc('sin(x)/x*sin(y)/y');
subplot(2,2,4);
ezsurfc('sin(x*y)/(x*y)');
MATLAB
4-1
4-13plotxyz091.m
sin(x)/x sin(y)/y
sin(x y)/(x y)
-1
5
-1
0
y
-5
-5
0
y
sin(x)/x sin(y)/y
1
-1
5
-1
-5
-5
0
x
-5
sin(x y)/(x y)
-5
5
0
y
-5
-5
0
x
MATLAB
4-2
hidden off
MATLAB
hidden off
hidden on
4-14plotxyz10.m
[x,y,z] = peaks;
mesh(x,y,z);
hidden off
axis tight
MATLAB
4-2
4-14plotxyz10.m
-5
2
0
-2
-3
-2
-1
MATLAB
4-2
on/off
hidden
on/off
onoff
zoom on/off
onoff
rotate3d
on/off
onoff
axis on/off
onoff
box on/off
onoff
hold on/off
on
off
more on/off
onoff
echo on/off
onoff
MATLAB
4-2
rotate3d on
3D
peaks
rotate3d on
MATLAB
4-2
Azimuth
Elevation
z
Elevation
x
Azimuth
MATLAB
4-2
Azimuth = 0
Elevation = 90
Azimuth = -37.5Elevation = 30
view
4-15plotxyz11.m
peaks;
view([0,-30]);
MATLAB
4-2
4-15plotxyz11.m
Peaks
8
6
4
2
-2
-4
2
-6
-3
-2
-1
0
x
-2
MATLAB
4-2
NaN
NaN nanNot a
Number
MATLAB NaN
4-16plotxyz12.m
[X, Y, Z] = peaks;
Z(10:20,10:20) = nan;
surf(X, Y, Z);
axis tight
% Z nan
MATLAB
4-2
4-16plotxyz12.m
-5
2
0
-2
-3
-2
-1
MATLAB
4-3
colorbar
colorbar MATLAB
peakscolorbar
Peaks
8
2
0
0
-5
-2
-4
2
0
-2
-6
MATLAB
4-3
RGB
Red
Green
Blue
black
white
red
green
blue
yellow
magenta
cyan
gray
0.5
0.5
0.5
dark red
0.5
copper
0.62
0.4
aquamarine
0.49
0.83
MATLAB
4-3
colormap
MATLAB colormap
>> cm = colormap;
>> size(cm)
ans =
64
cm 643 MATLAB
cm
cm
MATLAB
4-3
colormap
colormap
4-17plotxyz13.m
peaks;
colormap(rand(64,3));
colorbar;
MATLAB
4-3
4-17plotxyz13.m
Peaks
8
2
0
0
-5
-2
-4
2
0
-2
-2
x
-6
MATLAB
4-3
MATLAB
colormap hsv
HSV
colormap hot
colormap cool
colormap summer
colormap gray
colormap copper
colormap autumn
colormap winter
colormap spring
colormap bone
colormap pink
colormap flag
MATLAB
4-3
cool
4-18plotxyz14.m
peaks;
colormap cool;
colorbar
MATLAB
4-3
4-18plotxyz14.m
Peaks
8
2
0
0
-5
-2
-4
2
0
-2
-2
x
-6
MATLAB
4-3
surfmesh
surf mesh
4
4-19plotxyz15.m
[X, Y, Z] = peaks;
surf(X, Y, Z, gradient(Z));
axis tight;
colormap hot
MATLAB
4-3
4-19plotxyz15.m
-5
2
0
-2
-3
-2
-1
MATLAB
4-3
surfmesh
4-20plotxyz16.m
[X, Y, Z] = peaks;
surf(X, Y, Z, del2(Z));
axis tight;
colormap hot
MATLAB
4-3
4-20plotxyz16.m
-5
2
0
-2
-3
-2
-1
MATLAB
4-3
briten
brighten
4-21plotxyz17.m
colormap copper
subplot(3, 1, 1); rgbplot(colormap);
brighten(colormap, 0.5)
subplot(3, 1, 2); rgbplot(colormap);
brighten(colormap, -0.8)
subplot(3, 1, 3); rgbplot(colormap);
MATLAB
4-3
4-21plotxyz17.m
-5
2
0
-2
-3
-2
-1
MATLAB
4-3
True Color
MATLAB
Indexed Color
24
2^24
True Color
MATLAB
4-3
4-22plotxyz18.m
Z = peaks(50);
C(:, :, 1) = rand(50);
% C(:,:,1) RRed
C(:, :, 2) = rand(50);
% C(:,:,2) GGreen
C(:, :, 3) = rand(50);
% C(:,:,3) BBlack
subplot(1,1,1);
surf(Z, C);
axis tight
MATLAB
4-3
4-22plotxyz18.m
MATLAB
4-3
shading
shading
peaks
shading interp
MATLAB
4-3
shading interp
Bilinear Interpolation
shading flat
shading
faceted
MATLAB
4-3
colormapshading
colormap shading
4-23plotxyz19.m
surfl(peaks);
axis tight
colormap(pink);
shading interp
MATLAB
4-3
4-23plotxyz19.m