我使用以下内容在图表上标记了cos(x)
,cos(2x)
和cos(3x)
:
x=linspace(0,4*pi,50); y=cos(x)
plot(x,y)
y2 = cos(2*x)
hold on, plot(x,y2)
y3 = cos(3*x)
hold on, plot(x,y3)
grid on
xlabel (‘x’), ylabel(‘y’)
legend (‘y=cos(x)’, ‘y=cos(2x)’,’y=cos(3x)’)
如何使用矩阵以不同方式实现?如果我使用:cos(x)
创建代表cos(2x)
,cos(3x)
和Y=[sin(x) sin(2*x) sin(3*x)]
的3列圆柱。在这之后我会怎么做?我输入plot(x,Y)
但是说Error using plot. Vectors must be the same length.
也许这是显而易见的事情,但最近才开始使用MATLAB。提前谢谢。
答案 0 :(得分:3)
您使用空格水平连接(即创建一个长度为x
长度的三倍的长向量)。如果使用;
垂直连接来创建3x50
矩阵,一切都会好的:
x = linspace(0,4*pi,50);
Y = [cos(x);cos(2*x);cos(3*x)];
plot(x,Y);