Home I want to plot line with 3 colors on MATLAB

# I want to plot line with 3 colors on MATLAB

smhuh
1#
smhuh Published in 2017-12-07 16:23:39Z
 I have 3 variables, x, y, z. I want to plot line with 3 colors, red at h=0, green at h=1, blue at 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]; 
farbiondriven
2#
 Try this: 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');