Flush event queue and update figure window
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.
drawnow update causes only user-interface objects to refresh, if needed. Does not allow callbacks to execute and does not process other events pending in the queue.
Combine the expose and update options to obtain both effects:
drawnow expose update
Other events that cause the MATLAB® software to flush the event queue and draw the figure include:
Returning to the MATLAB prompt
Executing the following functions:
Functions that wait for user input (i.e., waitforbuttonpress, waitfor, ginput)
Any code that causes one of the above functions to execute. For example, suppose h is the handle of an axes. Calling axes(h) causes its parent figure to be made the current figure and brought to the front of all displayed figures, which results in the event queue being flushed.
Using drawnow in a loop causes the display to update while the loop executes:
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') % Evaluate y in the function workspace drawnow end