calvin tiger
calvin tiger

Reputation: 391

Display images within a loop without user intervention

In Matlab, I have a loop that performs operations on arrays. I would like to display the array at each iteration (using "imagesc" for instance), but without needing user intervention.

I can force Matlab to update the displayed figure by inserting the command "pause" after imagesc, but it needs to be dismissed by a key press. Without the "pause" command, the figure is not updated before the end of the loop.

Is there a way to update the figure at each iteration of the loop ?

Upvotes: 4

Views: 3053

Answers (2)

gtownescapee
gtownescapee

Reputation: 156

If drawnow updates too quickly, you can control the "frame rate" slightly better with pause(time_in_seconds). E.g., to pause for 0.5 seconds use

for ...
   % plot stuff
   pause(0.5);
end

Upvotes: 2

mathematical.coffee
mathematical.coffee

Reputation: 56935

Try using Matlab command drawnow after the graphing code within the loop.

drawnow causes figure windows and their children to update, and flushes the system event queue. Any callbacks generated by incoming events (e.g., mouse or key events) are dispatched before drawnow returns.

Upvotes: 4

Related Questions