就是这样:
% Your two points
P1 = [0,0,0];
P2 = [13,-11,19];
% Their vertial concatenation is what you want
pts = [P1; P2];
% Because that's what line() wants to see
line(pts(:,1), pts(:,2), pts(:,3))
% Alternatively, you could use plot3:
plot3(pts(:,1), pts(:,2), pts(:,3))
诚然,乍一看这似乎有点违反直觉,但从长远来看,这是有道理的。
如果你读过doc plot
or doc line
,你会发现每个人都期望sets of x
, y
and z
数据,分别。也就是说,使用
plot3(X,Y,Z)
with X
, Y
and Z
一些矩阵,plot3
将从第一条线开始画一条线triplet (X(1) Y(1) Z(1)
) 到第二个三元组 (X(2) Y(2) Z(2)
)等等——同样如此line
.