I'm doing a project and when I run my code, instead of MATLAB plotting the results after every time-step, it's only plotting the end result. I tried using the wait and timeout function but was unsuccessful. If anyone could help me put a 0.5 sec delay so MATLAB has the chance to plot that would be great!

 採用された回答

Matt Fig
Matt Fig 2011 年 5 月 12 日

2 投票

Do you call PLOT after every time-step? After every time-step, call PLOT then cal DRAWNOW. You can also call PAUSE with a time-to-pause argument, but I doubt this is what you really want to do with your code.

1 件のコメント

Zach
Zach 2011 年 5 月 12 日
thank you!

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2011 年 5 月 12 日

1 投票

pause(0.5)

14 件のコメント

Doug Hull
Doug Hull 2011 年 5 月 12 日
To flush the graphics queue, DRAWNOW is preferred.
Zach
Zach 2011 年 5 月 12 日
thank you!
Sean de Wolski
Sean de Wolski 2011 年 5 月 12 日
Yes, but if only drawnow is used then it'll still zip right through and show only the end result. Hence is they want to see each time point, a pause() is still necessary.
Sean de Wolski
Sean de Wolski 2011 年 5 月 12 日
x = 1:10;
y = x.^2;
figure;
hold on
for ii = 1:10
plot(x(ii),y(ii),'r*');
drawnow;
pause(0.5) %comment me to see the difference
end
Matt Tearle
Matt Tearle 2011 年 5 月 12 日
Well, it's not showing only the end result, it's just that it's too quick for the eye to catch the intermediate steps.
Sorry, I'm a pedant. But the bottom line is correct: use drawnow to flush the queue *and* (usually) pause to control the animation timing.
Matt Fig
Matt Fig 2011 年 5 月 12 日
Also, it would depend on what the user meant by timestep. I was picturing a lengthy calculation that would allow for more of a natural pause using DRAWNOW.
Also, setting the axis limits at the start is always a good idea for these types of things!
x = 1:10;
y = x.^2;
figure;
axis([0 10 0 100])
hold on
for ii = 1:10
plot(x(ii),y(ii),'r*');
sort(rand(3000)); % Simulate lengthy calculation
drawnow;
end
Matthew Simoneau
Matthew Simoneau 2011 年 5 月 12 日
FYI, I opened up a related discussion in a new question: http://www.mathworks.com/matlabcentral/answers/7309-is-pause-a-superset-of-drawnow
Jiro Doke
Jiro Doke 2011 年 5 月 12 日
@Matt Tearle,
I don't believe that "it's just too quick for the eye". I think it's because of the event queue issue. In other words, if you were to record the screen with a high-speed camera, you probably still won't be able to see the intermediate plots.
Unfortunately, I don't have a high-speed camera handy so I can't verify...
Matt Fig
Matt Fig 2011 年 5 月 12 日
@Jiro and Matt Tearle,
I can see the intermediate plots if the ax-lims are held before the loop! Perhaps I need a faster computer...
Jiro Doke
Jiro Doke 2011 年 5 月 12 日
@Matt Fig,
You mean without "drawnow"??
@Matt Tearle,
Darn hidden comments. I think I didn't see the whole thread of comments, so I thought you were referring to the OP's question, not to Sean's comment.
Matt Fig
Matt Fig 2011 年 5 月 12 日
@Jiro,
I mean the code I pasted in comment 6, but without the call to SORT. It is fast, but I definitely see it changing...
My new laptop should be here tomorrow, so I may not see it then.
Jiro Doke
Jiro Doke 2011 年 5 月 12 日
@Matt Fig,
Oh, I see. Yeah, I also see it with the drawnow. The question is whether it's updating faster than 30 Hz. My monitor refreshes at 60 Hz, so Nyquist frequency is 30.
Matt Tearle
Matt Tearle 2011 年 5 月 13 日
Thanks, Jiro. I think you've just made a business case for me needing a new computer... :)
Ghenam Dahmane
Ghenam Dahmane 2022 年 11 月 4 日
thanks so match

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

タグ

質問済み:

2011 年 5 月 12 日

コメント済み:

2022 年 11 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by