Matlab繪制三維曲線
在使用Matlab進行數(shù)據(jù)處理時,展示結(jié)果常常需要繪制三維曲線。本文將介紹如何使用Matlab繪制三維曲線。 plot3函數(shù)的使用 繪制三維曲線需要使用到plot3函數(shù)。plot3函數(shù)的功能是在三
在使用Matlab進行數(shù)據(jù)處理時,展示結(jié)果常常需要繪制三維曲線。本文將介紹如何使用Matlab繪制三維曲線。
plot3函數(shù)的使用
繪制三維曲線需要使用到plot3函數(shù)。plot3函數(shù)的功能是在三維空間中繪制曲線。與plot函數(shù)類似,plot3函數(shù)也是通過點來繪制曲線。不同之處在于,plot3函數(shù)使用三維坐標點集來繪制曲線。plot3函數(shù)的調(diào)用語法為:plot3(x1, y1, z1),其中x1、y1、z1是相同維數(shù)的向量,分別存儲各個點的坐標。對于曲線屬性的設(shè)置,可以參考其他設(shè)置方法。同時,對圖形屬性的設(shè)置也是一樣的。有關(guān)plot3函數(shù)的詳細說明,可以使用help plot3命令查看Matlab系統(tǒng)自帶的幫助信息。
示例:Matlab自帶的plot3例子
下面是一個由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');
有趣的三維曲線
接下來,我們用plot3函數(shù)繪制幾個有趣的三維圖形:
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;
不同視角的觀察
我們從不同角度觀察上述繪制的圖形,以下是從不同方向上觀察到的結(jié)果:
從z軸方向觀察
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軸方向觀察
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]方向觀察
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]方向觀察
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]);