matlab绘制立体图
基本XYZ立體繪圖命令
在科學(xué)目視表示(Scientific visualization)中,三度空間的立體圖是一個(gè)非常重要的技巧。本文將介紹MATLAB基本XYZ三度空間的各項(xiàng)繪圖命令。 ?
mesh和plot是三度空間立體繪圖的基本命令,mesh可畫出立體網(wǎng)狀圖,plot則可畫出立體曲面圖,兩者產(chǎn)生的圖形都會(huì)依高度而有不同顏色。下列命令可畫出由函數(shù)形成的立體網(wǎng)狀圖:
x=linspace(-2, 2, 25); % 在x軸上取25點(diǎn)
y=linspace(-2, 2, 25); % 在y軸上取25點(diǎn)
[xx,yy]=meshgrid(x, y); % xx和yy都是21x21的矩陣
zz=xx.*exp(-xx.^2-yy.^2); % 計(jì)算函數(shù)值,zz也是21x21的矩陣
mesh(xx, yy, zz); % 畫出立體網(wǎng)狀圖
surf和mesh的用法類似:
x=linspace(-2, 2, 25); % 在x軸上取25點(diǎn)
y=linspace(-2, 2, 25); % 在y軸上取25點(diǎn)
[xx,yy]=meshgrid(x, y); % xx和yy都是21x21的矩陣
zz=xx.*exp(-xx.^2-yy.^2); % 計(jì)算函數(shù)值,zz也是21x21的矩陣
surf(xx, yy, zz); % 畫出立體曲面圖
為了方便測(cè)試立體繪圖,MATLAB提供了一個(gè)peaks函數(shù),可產(chǎn)生一個(gè)凹凸有致的曲面,包含了三個(gè)局部極大點(diǎn)及三個(gè)局部極小點(diǎn),其方程式為:
要畫出此函數(shù)的最快方法即是直接鍵入peaks:
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)
我們亦可對(duì)peaks函數(shù)取點(diǎn),再以各種不同方法進(jìn)行繪圖。meshz可將曲面加上圍裙:
[x,y,z]=peaks;
meshz(x,y,z);
axis([-inf inf -inf inf -inf inf]);
waterfall可在x方向或y方向產(chǎn)生水流效果:
[x,y,z]=peaks;
waterfall(x,y,z);
axis([-inf inf -inf inf -inf inf]);
下列命令產(chǎn)生在y方向的水流效果:
[x,y,z]=peaks;
waterfall(x',y',z');
axis([-inf inf -inf inf -inf inf]);
meshc同時(shí)畫出網(wǎng)狀圖與等高線:
[x,y,z]=peaks;
meshc(x,y,z);
axis([-inf inf -inf inf -inf inf]);
surfc同時(shí)畫出曲面圖與等高線:
[x,y,z]=peaks;
surfc(x,y,z);
axis([-inf inf -inf inf -inf inf]);
contour3畫出曲面在三度空間中的等高線:
contour3(peaks, 20);
axis([-inf inf -inf inf -inf inf]);
contour畫出曲面等高線在XY平面的投影:
contour(peaks, 20);
plot3可畫出三度空間中的曲線:
t=linspace(0,20*pi, 501);
plot3(t.*sin(t), t.*cos(t), t);
亦可同時(shí)畫出兩條三度空間中的曲線:
t=linspace(0, 10*pi, 501);
plot3(t.*sin(t), t.*cos(t), t, t.*sin(t), t.*cos(t), -t);
from:http://shumozxf.blog.sohu.com/60505324.html
總結(jié)
以上是生活随笔為你收集整理的matlab绘制立体图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: word编辑论文技巧
- 下一篇: matlab平面绘图命令