我想在MATLAB上用3种颜色绘制线

我想在MATLAB上用3种颜色绘制线,matlab,plot,colors,line,Matlab,Plot,Colors,Line,我有3个变量,x,y,z。 我想用3种颜色绘制线,h=0时为红色,h=1时为绿色,h=2时为蓝色 x = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]; y = [0 1 2 1 3 4 7 9 8 6 5 3 2 1 0]; h = [0 0 0 0 0 1 1 1 1 1 2 2 2 2 2]; color = [1 0 0 ; 0 1 0 ; 0 0 1]; 试试这个: x = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]; y =

我有3个变量,x,y,z。 我想用3种颜色绘制线,h=0时为红色,h=1时为绿色,h=2时为蓝色

x = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14];
y = [0 1 2 1 3 4 7 9 8 6 5 3 2 1 0];
h = [0 0 0 0 0 1 1 1 1 1 2 2 2 2 2];
color = [1 0 0 ; 0 1 0 ; 0 0 1];
试试这个:

x = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14];
y = [0 1 2 1 3 4 7 9 8 6 5 3 2 1 0];
h = [0 0 0 0 0 1 1 1 1 1 2 2 2 2 2];
color = [1 0 0 ; 0 1 0 ; 0 0 1];


greens = h<1;
reds = h>=1;
blues = h>=2;

greenLine = y;
redLine = y;
blueLine = y;


greenLine(~greens) = NaN;

redLine(~reds) = NaN

blueLine(~blues) = NaN

plot(x,greenLine,'g',x,redLine,'r',x,blueLine,'b');
x=[012344567891011214];
y=[0113479865310];
h=[0 0 0 1 1 2 2 2];
颜色=[1 0;0 1 0;0 0 1];
绿色=h=1;
蓝色=h>=2;
绿线=y;
红线=y;
蓝线=y;
绿线(~greens)=南;
红线(~红色)=南
蓝线(~blues)=NaN
地块(x,绿线,'g',x,红线,'r',x,蓝线,'b');

非常感谢!从“xxxLine=h”更改为“xxxLine=y”后,它工作正常: