MATLAB: Plot Multiple Colours automatically in a for loop

colorcolormaphsvMATLABplot

Hi,
I am trying to plot a graph, with a different colour being used automatically for each line on the plot, is there a simple way to do this? Here is my code:
% Define a range of y values
y = [0:0.01:1];
hold on
% Create a loop, which calculates the velocity profile for each a_0
% coefficient in the range 0 => 2.67 with 0.267 increments:
for a_0 = [0:0.267:2.67];
for i = 1:length(y)
% Define boundary layer thickness delta as 99% U_inf
delta = 0.99;
% Define eta as a function of y position and the constant delta:
eta(i) = y(i)./delta;
% Calculate the velocity profile:
u_prof(i) = (a_0.*eta(i)) - ((((3./2).*a_0)-2).*(eta(i).^2)) - ((1- (a_0./2)).*(eta(i).^4));
end
% Plot the velocity profile for each a_0 coefficient
plot (u_prof,y)
grid on
end
hold off
Thanks,
Robbie

Best Answer

You should replace line
plot (u_prof,y)
with
plot (u_prof,y,'color',rand(1,3))