Plot a graph

3 次查看(过去 30 天)
zina ben
zina ben 2012-2-3
编辑: Matt J 2013-9-28
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

采纳的回答

Sean de Wolski
Sean de Wolski 2012-2-3
t=0:0.01:10;
a = [2 3];
x=a'*t;
y=sin(x);
plot(x',y')
  5 个评论
Sean de Wolski
Sean de Wolski 2012-2-3
This answer had that...
Walter Roberson
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
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
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
zina ben
zina ben 2012-2-3
But if i write a= input ('a')
and i chose any value of( a), after i need plot different graph with different value of( a )in the same figure

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by