Plot in real time

i have a code that i wrote to perform an output of simple harmonic function. and when i plot the result in realtime (as is it going through the for loop) rather than plotting y versus time, it is plotting two point (1,time) and (2,y) and draws a line in between.
any help is appreciated as i am new at using matlab
clf;
A=3.3;
W=6.28;
time=0;
p=0;
for t = (0:0.01:2)
y=A*sin(W*t);
time = time +0.01;
p=[time,y];
graph=plot(p);
drawnow;
p
pause(0.1)
end

Respuestas (1)

sixwwwwww
sixwwwwww el 2 de Dic. de 2013
Editada: sixwwwwww el 2 de Dic. de 2013

0 votos

Dear Jerry try this:
A = 3.3;
W = 6.28;
for t = 0:0.01:2
y = A * sin(W * t);
plot(t, y, 'g*'), hold on
drawnow;
pause(0.1)
end
I hope it helps. Good luck!

3 comentarios

Jerry
Jerry el 3 de Dic. de 2013
you are a genius, it worked, can you please tell me about the 'hold on' and explain to me why my original script did not work?
Jerry
Jerry el 3 de Dic. de 2013
how do make to be a line between the points?
sixwwwwww
sixwwwwww el 3 de Dic. de 2013
the 'hold on' command holds the current plot and then plots new data on the same graph without overwriting it. Secondly, in ur original you were plotting data wrongly

Iniciar sesión para comentar.

Categorías

Más información sobre Polar Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 2 de Dic. de 2013

Comentada:

el 3 de Dic. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by