MATLAB: Colormap for multiple plots

colormapplot

Hi,
I have a matrix K of size N x n and I plot the values of K on the same figure by using "hold on" n plots with N values each.
I would like to use a color map (from -1 to 1 , Blue to Red) in the following way: the n-th plot has color "0.4" or yellow if the first value of the column K(1,n) = 0.4 and so on.
How can I achieve this please?
Here is the code I have been trying to play with ( in particular adding the option 'Color' then 'jetcustom' in the plot options returns an error, I was trying to do like in this answer MathWorks Answer)
colormap(jet(n));
jetcustom=jet(n);
figure
x=1:k;
for i=1:n
y=K(:,i);
I=ismember(i,A);
J=ismember(i,B);
if I==1
plot(x,y,'--');
elseif J==1
plot(x,y);
end
hold on
end
xlim([1 k]);
ylim([-1.5 1.5])
colormap(jet(10))
cb=colorbar;
caxis([-1 1])

Best Answer

See my attached demo.