如何绘制线 s=(cost,sint,0) while 0<=t<=pi

How to plot line s=(cost,sint,0) while 0<=t<=pi

我想在 matlab 中绘制 s=(cost,sint,0) while 0<=t<=pi

t=0:.001:pi;
x=cos(t);
y=sin(t);
z=sin(t).*0;
mesh(x,y,z)

我收到 z 必须是矩阵的错误消息?我该如何继续?

你想要plot3, not mesh. The function mesh is used for plotting surfaces in 3D. For plotting lines in 3D you need plot3:

t=0:.001:pi;
x=cos(t);
y=sin(t);
z=sin(t).*0;
plot3(x,y,z)

请注意 z 可以更简单地定义为 z=zeros(size(t)):

t=0:.001:pi;
x=cos(t);
y=sin(t);
z=zeros(size(t));
plot3(x,y,z)

此外,由于 z 在您的情况下为零,您可以使用 plot for drawing the line in 2D, and then use view 更改为标准 3D 视图:

t=0:.001:pi;
x=cos(t);
y=sin(t);
plot(x,y)
view(3)

使用plot3(x, y, z).