matlab 程式設計入門篇 三維立體繪圖

Download MATLAB  程式設計入門篇 三維立體繪圖

If you can't read please download the document

Upload: lovie

Post on 07-Jan-2016

100 views

Category:

Documents


9 download

DESCRIPTION

MATLAB 程式設計入門篇 三維立體繪圖. 張智星 (Roger Jang) [email protected] http://mirlab.org/jang 清大資工系 多媒體檢索實驗室. 4-1 基本立體繪圖指令. mesh 和 surf : mesh :可畫出立體的「網狀圖」( Mesh Plots ) surf :可畫出立體的「曲面圖」( Surface Plots ) 範例 4-1: plotxyz001.m. z = [0 2 1; 3 2 4; 4 4 4; 7 6 8]; mesh(z); - PowerPoint PPT Presentation

TRANSCRIPT

  • MATLAB (Roger Jang)[email protected]://mirlab.org/jang

    MATLAB

    4-1 mesh surfmeshMesh PlotssurfSurface Plots4-1:plotxyz001.m

    z = [0 2 1; 3 2 4; 4 4 4; 7 6 8];mesh(z);xlabel('X = column index');% X ylabel('Y = row index');% Y

    MATLAB

    4-1 4-1 plotxyz001.m

    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 ylabel('Y = row index');% Y for i=1:size(z,1)for j=1:size(z,2)h=text(j, i, z(i,j), num2str(z(i, j))); % set(h, 'hori', 'center', 'vertical', 'bottom', 'color', 'r'); % endend

    MATLAB

    4-1 4-2 plotxyz002.m

    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] = meshgrid(x, y);% xx yy zz = xx.*yy;% zzsubplot(2,2,1); mesh(xx);title('xx'); axis tightsubplot(2,2,2); mesh(yy);title('yy'); axis tightsubplot(2,2,3); mesh(xx, yy, zz);title('zz xx yy '); axis tight

    MATLAB

    4-1 4-3 plotxyz011.m

    MATLAB

    4-4 plotxyz01.m linspace x = linspace(-2, 2, 25);% x [-2,2] 25 y = linspace(-2, 2, 25);% y [-2,2] 25 [xx, yy] = meshgrid(x, y);% xx yy 2525 zz = xx.*exp(-xx.^2-yy.^2);% zz 2525 mesh(xx, yy, zz);% 4-1

    MATLAB

    4-1 4-4 plotxyz01.m

    MATLAB

    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] = meshgrid(x, y);% xx yy 2525 zz = xx.*exp(-xx.^2-yy.^2);% zz 252 surf(xx, yy, zz);% 4-1

    MATLAB

    4-1 4-5 plotxyz02.m

    MATLAB

    4-1 peaksMATLAB peaks Local MaximaLocal Minima

    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

    MATLAB

    4-1 meshzmeshz 4-6plotxyz03.m[x, y, z] = peaks;meshz(x,y,z);axis tight;

    MATLAB

    4-1 4-6plotxyz03.m

    MATLAB

    4-1 waterfallwaterfall x y 4-7plotxyz04.m[x, y, z] = peaks;waterfall(x,y,z);axis tight;

    MATLAB

    4-1 4-7plotxyz04.m

    MATLAB

    4-1 meshcmeshc Contours 4-8plotxyz05.m[x, y, z] = peaks;meshc(x, y, z);axis tight;

    MATLAB

    4-1 4-8plotxyz05.m

    MATLAB

    4-1 plot3plot3 4-9plotxyz06.mt = linspace(0,20*pi, 501);% 0 20*pi 501 plot3(t.*sin(t), t.*cos(t), t);% tsin(t),tcos(t),t

    MATLAB

    4-1 4-9plotxyz06.m

    MATLAB

    4-1 plot34-10plotxyz07.mt = 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

    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

    MATLAB

    4-1 plot3MATLAB 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 onplot3(x, y, z, '.', 'MarkerSize', 16);% 100 hold offaxis tight

    MATLAB

    4-1 4-12plotxyz09.m

    MATLAB

    4-1

    mesh, ezmeshmeshc, ezmeshcmeshzsurf, ezsurfsurfc, ezsurfcsurfl

    MATLAB

    4-1

    plot3, ezplot3surfaceSurf line3Plot3 contour, ezcontourcontour3pcolor

    MATLAB

    4-1 ezmesh, ezsurf ezmesh ezsurf 4-13plotxyz091.msubplot(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

    MATLAB

    4-2 hidden offMATLAB 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

    MATLAB

    4-2 on/off

    hidden on/offonoffzoom on/offonoffrotate3d on/offonoffaxis on/offonoffbox on/offonoffhold on/offonoffmore on/offonoffecho on/offonoff

    MATLAB

    4-2 rotate3d on 3D peaks rotate3d on

    MATLAB

    4-2 Azimuth Elevation

    MATLAB

    4-2 Azimuth = 0Elevation = 90 Azimuth = -37.5Elevation = 30 view 4-15plotxyz11.mpeaks;view([0,-30]);

    MATLAB

    4-2 4-15plotxyz11.m

    MATLAB

    4-2 NaN NaN nanNot a NumberMATLAB NaN4-16plotxyz12.m

    [X, Y, Z] = peaks;Z(10:20,10:20) = nan;% Z nansurf(X, Y, Z);axis tight

    MATLAB

    4-2 4-16plotxyz12.m

    MATLAB

    4-3 colorbar colorbar MATLAB peakscolorbar

    MATLAB

    4-3 RGB

    RedGreenBlueblack000white111red100green010blue001yellow110magenta101cyan011gray0.50.50.5dark red0.500copper10.620.4aquamarine0.4910.83

    MATLAB

    4-3 colormapMATLAB colormap cm 643 MATLAB cm cm

    >> cm = colormap; >> size(cm) ans = 64 3

    MATLAB

    4-3 colormap colormap 4-17plotxyz13.m

    peaks;colormap(rand(64,3));% colorbar;

    MATLAB

    4-3 4-17plotxyz13.m

    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

    X

    colormap pink

    colormap flag

    MATLAB

    4-3 cool4-18plotxyz14.m

    peaks;colormap cool; colorbar

    MATLAB

    4-3 4-18plotxyz14.m

    MATLAB

    4-3 surfmeshsurf 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

    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

    MATLAB

    4-3 briten brighten 4-21plotxyz17.m

    colormap coppersubplot(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

    MATLAB

    4-3 True ColorMATLAB Indexed Color 24 2^24True Color

    MATLAB

    4-3 4-22plotxyz18.mZ = peaks(50);C(:, :, 1) = rand(50);% C(:,:,1) RRedC(:, :, 2) = rand(50);% C(:,:,2) GGreenC(:, :, 3) = rand(50);% C(:,:,3) BBlacksubplot(1,1,1);surf(Z, C);axis tight

    MATLAB

    4-3 4-22plotxyz18.m

    MATLAB

    4-3 shading shading peaksshading interp

    MATLAB

    4-3

    shading interp Bilinear Interpolation shading flatshading faceted

    MATLAB

    4-3 colormapshading colormap shading4-23plotxyz19.m

    surfl(peaks);% axis tightcolormap(pink);shading interp

    MATLAB

    4-3 4-23plotxyz19.m