Plot a graph
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have
t=0:0.01:10
x=a*t
y=sin(x)
and a has two values a=2, a=3
I want to plot (x, y) with two values of a in the same loop. Thanks in advance
0 件のコメント
採用された回答
Sean de Wolski
2012 年 2 月 3 日
t=0:0.01:10;
a = [2 3];
x=a'*t;
y=sin(x);
plot(x',y')
5 件のコメント
Walter Roberson
2012 年 2 月 3 日
Yes, Sean's solution should work just fine, and it is worth eventually studying how it works. It is a more advanced and less technique. But first you should study "hold on" as you will use that more in practice.
その他の回答 (1 件)
Walter Roberson
2012 年 2 月 3 日
t = 0 : 0.01 : 10
for a = 2 : 3
x = a .* t;
y = sin(x);
plot(x, y);
hold on % <---- THIS
end
Which is the same solution you were told in your two previous questions on the same topic.
3 件のコメント
Walter Roberson
2012 年 2 月 3 日
If you have a vector of inputs stored in "a", then
t = 0 : 0.01 : 10;
for thisa = a
x = thisa .* t;
y = sin(x);
plot(x, y);
hold on % <---- THIS
end
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!