Here is a simple option:
x = linspace(-4*pi,4*pi,10000); % some data
y = -sin(x); % some data
N = 4;
py = reshape(y,[],N);
px = reshape(x,[],N);
plot(px,py,'LineWidth',2)
Where y
is your vector, and N
is the number of pieces you want to distinguish. Note that you have to make sure that y
is dividable by N
with no remainder.
If you want to set the colors, you can do this with set
command:
p = plot(px,py,'LineWidth',2)
cmap = parula(N); % a set of N colors in RGB matrix
set(p,{'color'},mat2cell(cmap,ones(N,1),3))
and you get: