MATLAB: Help with changing colors in looped figure

change colorscolorfigurefor loophold oniterationplot

Hello,
I have a code that loops through a dataset of current velocity profiles through the water column, and can't figure out how to change the color of the plotted line with each iteration. Here is the code as is:
figure
set(gcf, 'Position', get(0, 'Screensize'));
for fig=1:length(ur10)
plot(ur10(:,fig),z)
hold on
xlim([-1.8 2.2])
title('velocity profiles at low discharge','FontSize',17)
xlabel('velocity, positive landward (m/s)','FontSize',17)
ylabel('meters above bed','FontSize',17)
pause(.01)
end
I would like to be able to have each successive velocity profile plot in orange, but all those that have already plotted to remain on the figure in blue. This way I can see all the previous profiles but also differentiate the most recent one that plots for each loop iteration. Can someone assist? Thank you!

Best Answer

To specify the color you want you have to use
plot(x,y,'color','c') ;
Where c can be b,r,k,g,m,c etc. If you know the loop number define a cell of colors:
C = {'o' ; 'k' ; 'b'} ;
And call the color inside the loop using c{i}.
Also you can define color as 1x3 RGB array. Simply use rand(1,3) .
plot(x,y,'color',rand(1,3))