MATLAB: How to assign a different color to lines being plotted in a loop

3d plotsarrayfor looploopplotplotting

Hi All
I am plotting n different lines in one single plot. but what I need it to assign a different color ( even random) for each iteration. and then use it as a Legend.
How do I do this ?

Best Answer

* Edits: Sorry for the wrong information about the default line color.
Otherwise, you can try
figure
hold on
randColor = rand(10,3);
for i = 1:10
plot(x(:,i),y(:,i),'Color',randColor(i,:));
end
legend
But the color would be ugly. Instead of rand, you can try other available colormap. For example
figure
hold on
cm = parula(10);
for i = 1:10
plot(x(:,i),y(:,i),'Color', cm(i,:));
end
legend
Related Question