How to change the color of the graph at each iteration in MATLAB?

The following is part of my code in Matlab. As shown, I would like to plot 8 curves on a single graph. But I want to make each curve one unique color. I also want to change the legend so that it changes for everyone i.

For example, for i = 1 the legend would be gho-1, for i = 2 gho-2 and so on. I want this to be automatic, because I sometimes change ito ex: (i = 1: 20).

for i=1:8
.
.
.
plot(b,r,'b');
legend(['qho-',num2str(i)]);    
hold on
end

How can i do this?

Hi,

I have another question: if I have the following

for i=1:8
.
b1=(1:3,:)
b2=(3:6,:)
figure(1);plot(b1,r,'*');
figure(2);plot(b2,r,'*');

Leg{i} = ['qho-',num2str(i)];    

end
legend(Leg)

I have only a color legend only for the last figure. not for both .. how can I solve this ?!

Thanks again

+5
source share
2 answers

hold all hold on

hold all
for i=1:8
    .
    .
    .
    plot(b,r);

    Leg{i} = ['qho-',num2str(i)];    

end
legend(Leg)

. , : Matlab


:

Matlab R2014b , hold on , hold all, .. , . , hold all .

+8

- :

figure, hold on
N = 8;
h = zeros(N,1);    %# store handle to line graphic objects
clr = lines(N);    %# some colormap
for i=1:N
    %# plot random data
    y = cumsum(randn(100,1));
    h(i) = plot(y, 'Color',clr(i,:));
end
hold off
legend(h, num2str((1:N)','gho-%d'))    %# display legend

plot

+7

All Articles