matlab timer 调用函数set,Matlab Timer回调函数的执行问题----drawnow函数的用途

由前一篇文章可以看出,按照所设定的时间间隔调用Timer的回调函数时,并不是真的即刻执行该回调函数,而是先将该回调函数放入事件队列中,待前面的事件都执行完时才执行该事件。但有时我们需要当所设定的时间到达时立刻执行我们的回调函数,此时我们就可以用功能强大的drawnow函数了。在回调函数中加入drawnow就可以在时间到达时强制执行该回调函数。

下面给出的是matlab帮助里关于drawnow的用法:

drawnow

Flush event queue and update figure window

Syntax

drawnow

drawnow expose

drawnow update

Description

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 expose causes only graphics objects to refresh, if needed. It does not allow callbacks to execute and does not process other events in the queue.

drawnow update causes only non-graphics objects to refresh, if needed. It does not allow callbacks to execute and does not process other events in the queue.

You can combine the expose and update options to obtain both effects.

drawnow expose update

Other Events That Cause Event Queue Processing

Other events that cause MATLAB to flush the event queue and draw the figure includes:

*

Returning to the MATLAB prompt

*

Executing the following functions

o

figure

o

getframe

o

input

o

keyboard

o

pause

*

Functions that wait for user input (i.e., waitforbuttonpress, waitfor, ginput)

*

Any code that causes one of the above functions to be executed. 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.

Examples

Using drawnow in a loop causes the display to update while the loop executes:

t = 0:pi/20:2*pi;y = exp(sin(t));h = plot(t,y,'YDataSource','y');for k = 1:.1:10 y = exp(sin(t.*k)); refreshdata(h,'caller') % Evaluate y in the function workspace drawnow; pause(.1)end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值