how to use Arrays for plotting curves in for loop

Hi all,
I need some help here
I have to plot multiple curves on same graph for eg
t=0:.1:6
y1=sin(t)
y2=sin(2t)
y3=sin(3t)
.
.
.
and have to plot all this y1,y2,y3... w.r.t t on the same graph with different colors and linestyles
Since they are large in no i want to use an array for y1,y2,... and a for loop to define them and plot them all.
How can this be done????

 採用された回答

Youssef  Khmou
Youssef Khmou 2013 年 12 月 15 日

1 投票

kiran, that can be done efficiently if you store all the ys in one matrix :
t=0:0.1:6;
y=zeros(length(t),3);
y(:,1)=sin(t);
y(:,2)=sin(2*t);
y(:,3)=sin(3*t);
plot(t,y)

1 件のコメント

kiran
kiran 2013 年 12 月 19 日
編集済み: kiran 2013 年 12 月 19 日
thank you.. youssef

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 12 月 15 日

0 投票

t = (0:.1:6)';
y = sin(t*(1:3));
plot(t,y);

1 件のコメント

kiran
kiran 2013 年 12 月 19 日
thank you, Anderi but i find it difficult to pick up y (y1,y2...) on some conditions

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

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2013 年 12 月 15 日

コメント済み:

2013 年 12 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by