Documentation

drawnow

Update figures and process callbacks

Syntax

drawnow
drawnow limitrate
drawnow nocallbacks
drawnow limitrate nocallbacks
drawnow update
drawnow expose

Description

example

drawnow更新数字和处理任何未决回调。如果修改图形对象,请使用此命令,并希望立即查看屏幕上的更新。

example

drawnowlimitratelimits the number of updates to 20 frames per second. If it has been fewer than 50 milliseconds since the last update, or if the graphics renderer is busy with the previous change, thendrawnow丢弃新更新。如果要在循环中更新图形对象,则使用此命令,而无需查看屏幕上的每个更新。跳过更新可以创建更快的动画。正在处理未决的回调,因此您可以在动画过程中与数字进行交互。

drawnowNocallbacksdefers callbacks, such as theButtonDownFcncallback, until the next fulldrawnowcommand. Use this option if you want to prevent callbacks from interrupting your code. Deferring callbacks temporarily disables figure interactions, such as mouse clicks or resizing the figure. Deferring callbacks does not affect animation speed.

drawnowlimitrateNocallbackslimits the number of updates to 20 frames per second and skips updates if the renderer is busy. This syntax also prevents callbacks from interrupting your code, which temporarily disables figure interactions.

drawnowupdateskips updates if the renderer is busy and defers callbacks. This syntax is not recommended. Use thelimitrateoption instead.

drawnowexpose更新数字,但防御回调。不建议使用此语法。使用Nocallbacksoption instead.

Examples

collapse all

创建一个生长的动画,因为它积累了2,000个数据点。采用drawnowto display the changes on the screen after each iteration through the loop.

h = animatedline; axis([0 4*pi -1 1]) x = linspace(0,4*pi,2000);fork = 1:length(x) y = sin(x(k)); addpoints(h,x(k),y); drawnowend

Create an animation of a line growing as it accumulates 10,000 points. Since there are 10,000 points, drawing each update on the screen is slow. Create a faster, smooth animation by limiting the number of updates usingdrawnow limitrate. Then, display the final updates on the screen by callingdrawnowafter the loop ends.

h = animatedline; axis([0 4*pi -1 1]) x = linspace(0,4*pi,10000);fork = 1:length(x) y = sin(x(k)); addpoints(h,x(k),y); drawnowlimitrateend

drawnow

Compute all the data before the animation loop.

h = animatedline; axis([0 4*pi -1 1]) x = linspace(0,4*pi,10000); y = sin(x);fork = 1:length(x) addpoints(h,x(k),y(k)); drawnowlimitrateend

drawnow

If you have long computations, precomputing the data can improve perfomance. Precomputing minimizes the computation time by letting the computation run without interruptions. Additionally, it helps ensure a smooth animation by focusing on only graphics code in the animation loop.

More About

collapse all

Actions Equivalent todrawnow

These actions are equivalent to calling a fulldrawnowcommand:

Tips

  • TheNocallbacks选项始终将中断回调添加到队列中。如果要丢弃中断回调,请使用InterruptibleBusyActionproperties instead.

Introduced before R2006a

Was this topic helpful?