Matlab 使用一个矩阵绘制几条直线

Matlab 使用一个矩阵绘制几条直线,matlab,graph,plot,Matlab,Graph,Plot,假设我有两个矩阵x和y x=[1 2 3 1 2] y=[1 2 3 1 3] 我想画两条线,前三个点,然后最后两个点 最后我想得到这个情节。我能用Matlab做吗 使用按住所有键在同一轴上绘制多条线 figure plot( x(1:3), y(1:3) ); hold all; plot( x(4:end), y(4:end) ); 使用hold all在同一轴上绘制多条线 figure plot( x(1:3), y(1:3) ); hold all; plot( x(4:end), y

假设我有两个矩阵x和y

x=[1 2 3 1 2] y=[1 2 3 1 3]

我想画两条线,前三个点,然后最后两个点

最后我想得到这个情节。我能用Matlab做吗


使用
按住所有键
在同一轴上绘制多条线

figure
plot( x(1:3), y(1:3) );
hold all;
plot( x(4:end), y(4:end) );

使用
hold all
在同一轴上绘制多条线

figure
plot( x(1:3), y(1:3) );
hold all;
plot( x(4:end), y(4:end) );
使用索引指定
绘图的坐标向量输入参数对

plot(x(1:3), y(1:3), x(4:5), y(4:5))
使用索引指定
绘图的坐标向量输入参数对

plot(x(1:3), y(1:3), x(4:5), y(4:5))
试试这个

plot(x(1:3),y(1:3),'b',x(4:end),y(4:end),'r')
试试这个

plot(x(1:3),y(1:3),'b',x(4:end),y(4:end),'r')