%% 繪制三維曲線
%plot3函數,其中每一組x,y,z組成一組曲線的坐標參數,選項的定義和plot函數相同。
%1、當x,y,z是同維向量時,則x,y,z 對應元素構成一條三維曲線。
x0 = 0:pi/50:10*pi;
y0 = sin(x0);z0 = cos(x0);
y0=y0';
%將y轉置為列向量試試
plot3(x0,y0,z0);grid
on
;
%不影像結果
title(
'Line in 3-D Space'
);
%2、當x,y,z是同維矩陣時,則以x,y,z對應列元素繪制三維曲線,曲線條數等於矩陣_列數_
x1(:,1)=0:pi/50:10*pi;
x1(:,2)=-13*pi:pi/50:-3*pi;
y1 = sin(x1); z1 = cos(x1);
plot3(x1,y1,z1);grid
on
;
%3、如果X,Y,Z中有向量也有矩陣,則向量是根據矩陣的行_或_列繪制
%depending whether the vectors' lengths equal the number of rows or the number of columns.
plot3(x0,y1,z1);grid
on
;
%可見x軸的范圍仍是x0的范圍
xlabel(
'x'
);ylabel(
'y'
);zlabel(
'z'
);
%第一條線是 x0,y1(:,1),z1(:,1)
%第二條線是 x0,y1(:,2),z1(:,2)
%%%%%證明如下:
figure;
plot3(x0,y1(:,1),z1(:,1)); hold
on
;
plot3(x0,y1(:,2),z1(:,2)); hold
off
;
xlabel(
'x'
);ylabel(
'y'
);zlabel(
'z'
);
%%%%%證明完畢
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">