Documentation

drawnow

Update figure window and execute pending callbacks

Syntax

drawnow
drawnow expose
drawnow update

Description

drawnow updates all graphics and UI objects and executes any pending callbacks by flushing the system queue. Use drawnow in animation loops to update the figure during function execution.

drawnow expose updates all graphics and UI objects, but does not flush the system queue. This option defers callbacks until the next system queue flush.

drawnow update updates all graphics and UI objects only if the graphics renderer is free. Otherwise, it discards the updates. This option defers callbacks until the next system queue flush.

Other Actions that Flush the System Queue

These are other actions that flush the system queue:

  • Returning to the MATLAB® prompt

  • Executing one of these functions:

    • figure

    • getframe

    • input

    • pause

    • keyboard

  • Executing waitforbuttonpress, waitfor, ginput or other functions that wait for user input

  • Any code that causes one of the above functions to execute. For example, suppose ax is an axes object. Calling axes(ax) causes the parent figure to be made the current figure and brought to the front of all displayed figures, which is equivalent to executing a drawnow command.

Display Updates After Each Loop Iteration

Use drawnow to display the updates after each iteration through the loop.

t = 0:pi/100:2*pi;
y = exp(sin(t));
h = plot(t,y,'YDataSource','y');
for k = 1:0.01:10
   y = exp(sin(t.*k));
   refreshdata(h,'caller')
   drawnow
end

Was this topic helpful?