The following is a part of my matlab code. As it\'s shown, I would like to plot 8 curves in one plot. But I want to make each curve with one unique color. I also want to cha
Just use hold all
instead of hold on
and put the legend labels in a cell array
hold all
for i=1:8
.
.
.
plot(b,r);
Leg{i} = ['qho-',num2str(i)];
end
legend(Leg)
See this question for example: Sparse matrix plot matlab
NOTE:
From Matlab R2014b onward, hold on
has been modified to act like hold all
, i.e. change the colours of the plots each time one is plotted. The docs state that the hold all
syntax will be removed in future releases.
How about something like:
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