Automaticly generate plots and different legend

71 views (last 30 days)
john
john on 21 Mar 2013
Hi,
let k is variable. For example, if k=3, then I will have speed1 speed2 speed3.
How can I automaticly generate one plot with all speeds and also different legend for each one?
Thanks
ps:t=0:0.01:100

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 21 Mar 2013
Edited: Azzi Abdelmalek on 21 Mar 2013
t=0:0.01:100
speed1=cos(0.01*t);
speed2=sin(0.05*t);
speed3=cos(0.1*t);
y=[speed1;speed2;speed3];
plot(t',y');
for k=1:size(y,1)
leg{k}=sprintf('speed%d',k);
end
legend(leg);
  6 Comments
john
john on 25 Mar 2013
Hi, color for leg1 is blue, green, red and color for leg2 is again blue, green, red. I need generate different legends, so there is not possible to repeat any color. Can you help me please?
This is my code
for k=1:3;
leg1{k}=sprintf('speed_%d',k);
leg2{k}=sprintf('acceleration_%d',k);
end
legend = legend([leg1,leg2]);

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!