Matlab繪制三維曲線(xiàn)
在使用Matlab進(jìn)行數(shù)據(jù)處理時(shí),展示結(jié)果常常需要繪制三維曲線(xiàn)。本文將介紹如何使用Matlab繪制三維曲線(xiàn)。 plot3函數(shù)的使用 繪制三維曲線(xiàn)需要使用到plot3函數(shù)。plot3函數(shù)的功能是在三
在使用Matlab進(jìn)行數(shù)據(jù)處理時(shí),展示結(jié)果常常需要繪制三維曲線(xiàn)。本文將介紹如何使用Matlab繪制三維曲線(xiàn)。
plot3函數(shù)的使用
繪制三維曲線(xiàn)需要使用到plot3函數(shù)。plot3函數(shù)的功能是在三維空間中繪制曲線(xiàn)。與plot函數(shù)類(lèi)似,plot3函數(shù)也是通過(guò)點(diǎn)來(lái)繪制曲線(xiàn)。不同之處在于,plot3函數(shù)使用三維坐標(biāo)點(diǎn)集來(lái)繪制曲線(xiàn)。plot3函數(shù)的調(diào)用語(yǔ)法為:plot3(x1, y1, z1)
,其中x1、y1、z1是相同維數(shù)的向量,分別存儲(chǔ)各個(gè)點(diǎn)的坐標(biāo)。對(duì)于曲線(xiàn)屬性的設(shè)置,可以參考其他設(shè)置方法。同時(shí),對(duì)圖形屬性的設(shè)置也是一樣的。有關(guān)plot3函數(shù)的詳細(xì)說(shuō)明,可以使用help plot3
命令查看Matlab系統(tǒng)自帶的幫助信息。
示例:Matlab自帶的plot3例子
下面是一個(gè)由Matlab自帶的plot3函數(shù)生成的例子:
t 0:pi/50:10*pi; h plot3(sin(t), cos(t), t); xlabel('sin(t)'); ylabel('cos(t)'); zlabel('t'); grid on; axis square; set(h,'LineSmoothing','on');
有趣的三維曲線(xiàn)
接下來(lái),我們用plot3函數(shù)繪制幾個(gè)有趣的三維圖形:
t 0:pi/50:30*pi; x sin(t); y cos(t); x1 sin(2*t); y1 2*sin(0.5*t); subplot(2,2,1); plot3(x, y, t); grid on; subplot(2,2,2); plot3(x, y1, t); grid on; subplot(2,2,3); plot3(x1, y, t); grid on; subplot(2,2,4); plot3(x1, y1, t); grid on;
不同視角的觀(guān)察
我們從不同角度觀(guān)察上述繪制的圖形,以下是從不同方向上觀(guān)察到的結(jié)果:
從z軸方向觀(guān)察
subplot(2,2,1); grid on; view([0 0 1]); subplot(2,2,2); grid on; view([0 0 1]); subplot(2,2,3); grid on; view([0 0 1]); subplot(2,2,4); grid on; view([0 0 1]);
從x軸方向觀(guān)察
subplot(2,2,1); grid on; view([1 0 0]); subplot(2,2,2); grid on; view([1 0 0]); subplot(2,2,3); grid on; view([1 0 0]); subplot(2,2,4); grid on; view([1 0 0]);
從[1 0 1]方向觀(guān)察
subplot(2,2,1); grid on; view([1 0 1]); subplot(2,2,2); grid on; view([1 0 1]); subplot(2,2,3); grid on; view([1 0 1]); subplot(2,2,4); grid on; view([1 0 1]);
從[0 1 1]方向觀(guān)察
subplot(2,2,1); grid on; view([0 1 1]); subplot(2,2,2); grid on; view([0 1 1]); subplot(2,2,3); grid on; view([0 1 1]); subplot(2,2,4); grid on; view([0 1 1]);