Plot in real time

조회 수: 2 (최근 30일)
Jerry
Jerry 2013년 12월 2일
댓글: sixwwwwww 2013년 12월 3일
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

답변 (1개)

sixwwwwww
sixwwwwww 2013년 12월 2일
편집: sixwwwwww 2013년 12월 2일
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
Jerry
Jerry 2013년 12월 3일
how do make to be a line between the points?
sixwwwwww
sixwwwwww 2013년 12월 3일
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

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

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by