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일

0 개 추천

t=0:0.01:10;
a = [2 3];
x=a'*t;
y=sin(x);
plot(x',y')

댓글 수: 5

zina ben
zina ben 2012년 2월 3일
thinks,
but if a is un input and it can take any value what can i do
Sean de Wolski
Sean de Wolski 2012년 2월 3일
rewrite it as a function that takes a row vector a...
or if it takes a column vector a, you can skip the transpose in the calculation of x.
zina ben
zina ben 2012년 2월 3일
but i need the graphe for each one value of a in the same figure
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일

0 개 추천

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

zina ben
zina ben 2012년 2월 3일
thinks,
It is a simple idea
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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

질문:

2012년 2월 3일

편집:

2013년 9월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by