Automaticly generate plots and different legend

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

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 21 日
編集済み: Azzi Abdelmalek 2013 年 3 月 21 日

5 投票

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 件のコメント

john
john 2013 年 3 月 21 日
Hi, but how can I automaticly generate matrix y? I tried
y=[strcat('speed',num2str((1:k)'))];
but it doesnt work. Count of speeds is always different.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 21 日
How are you generating spped1 speed2 ...
john
john 2013 年 3 月 21 日
編集済み: john 2013 年 3 月 21 日
Now, I wrote it only manual like you
speed1=sin(a*t);
speed2=sin(a*t);
speed3=sin(a*t);
Where
for i=1:k;
a=result(i,1);
end;
Can you help me, how automaticly generate speeds and also matrix y for plot?
Maybe this is part of the solution:
for i=1:k;
a=result(i,1);
speed(:,i)=sin(a*t);
end;
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 21 日
編集済み: Azzi Abdelmalek 2013 年 3 月 21 日
close
t=0:0.01:100
result=[0.01 0.1 1]
for k=1:3;
a=result(k);
speed(:,k)=sin(a*t)';
leg{k}=sprintf('speed%d',k);
end;
plot(t',speed);
legend(leg);
john
john 2013 年 3 月 21 日
great....thank a lot ...I also generated acceleration with leg2...in the future, in guide, I would like to add check boxes. Count of check boxes will be based on number k, with possibility to show only checked speeds...it will be difficult?
john
john 2013 年 3 月 25 日
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]);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeParallel for-Loops (parfor) についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by