惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
D
Docker
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
宝玉的分享
宝玉的分享
腾讯CDC
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
T
The Exploit Database - CXSecurity.com
T
The Blog of Author Tim Ferriss
V
V2EX
S
Securelist
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Y
Y Combinator Blog
P
Proofpoint News Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
T
Threat Research - Cisco Blogs
B
Blog
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
N
News and Events Feed by Topic
博客园 - 司徒正美
H
Help Net Security
C
Cisco Blogs
C
Check Point Blog
S
Secure Thoughts

博客园 - febird

改进 GAE cpedialog 博客程序的一些细节 Python 格式化输出时间字符串函数 strftime 从IEEE802.1到IEEE802.22 CodeWarrior for Freescale S12 开发Tips - febird 第一个 Android 程序 [资料] IPv6主机地址 Web中使用MSCOMM32.OCX读写串口(2) Web中使用MSCOMM32.OCX读写串口 Matlab多窗口传值问题(GUI) My Matlab Tips (Unfinished) Matlab中使用Plot函数动态画图方法总结 Matlab GUIDE使用总结--Matlab GUI界面 Matlab Deploy工具的使用--Matlab生成可执行文件 使用matlab作为图表绘制工具--Matlab使用入门 基于DE2 与Nios II的音频录放系统的设计-软件篇 基于DE2 与Nios II的音频录放系统的设计-系统篇 GMail今天更换外观了-支持主题 Google WebMaster网站验证错误(404返回成功)解决方法 Febird.co.cc 恢复正常访问
Matlab中Timer的使用
febird · 2008-12-20 · via 博客园 - febird

  鉴于Matlab中缺乏多线程机制,使用Timer无疑是一个很重要的工具,Matlab中Timer是一个Java对象。

   Timer的定义

   t=timer();

   设置属性:

  eg.   set(t,'Name','your_timer_name');

  当然可以一次性设置完成:

  例如:

    TaskTimer=timer(...
    'Name','FebirdTimer',...
    'TimerFcn',@ExecuteTask,...
    'ErrorFcn',@ExecuteError,...
    'Period',1,...
    'ExecutionMode','fixedrate');  

  这里TimerFcn为Timer执行的函数,后面的 ‘@ExcuteTask’ 就是你定义的函数名
 同样 ErrorFcn也是一样。

  Period为执行周期,ExecutionMode为执行模式,fixedrate为固定频率。当然前面所说的都是在这个前提之上。

  关于TimerFcn的定义

  当以TimerFcn的定义默认必须有两个参数

  function ExcuteTask(obj,eventdata)
   % TODO
  end

  其中obj为执行该函数所对应的timer对象,eventdata为事件数据,一般里面为具体时间。

 当需要在ExcuteTask中传入参数的时候,那么Timer可以这样定义:

 set(t,'TimerFcn',{@ExecuteTask,var1});

 那么这时函数定义应该为:

 function ExcuteTask(obj,eventdata,var1)
   % TODO
 end

  其他函数的定义也类似。


  关于UserData

  UserData在Timer比较有用,因为当时用上面的方法传递参数是,Matlab只会在第一次传入参数。

  所以我们可以在UserData这个域中保存我们的数据

  例如
 
  t=[0]
  lh=plot(t,sin(t),'-');

   t=timer(...

   'Name','FebirdTimer',...

   'TimerFcn',@ExecuteTask,...

   'ErrorFcn',@ExecuteError,...

   'Period',1,...

   'ExecutionMode','fixedrate');

   ud=struct{'linehanle',lh,'count',0} ;

   set(t,'UserData',ud);

  function ExcuteTask(obj,eventdata)

    ud=obj.UserData;
    l=ud.linehandle;
    c=ud.count;
    t=get(l,'XData');
    y=get(l,'YData');
    t=[t count];
    y=[y sin(0.1*count)];
    set(lh,'XData',t,'YData',y);

   drawnow

   ud.count=ud.count+1;
   set(obj,'UserData',ud);

  end

以上给出了一个使用Timer画图的方法 


关于Timer的函数

 1.start();
 2.stop();
 3.timerfind();

 eg.删除所有的timer
 ts=timerfind;
 if length(ts)>0
 stop(ts);
 delete(ts);
 end

 通过Name查找特定的Timer:

 t=timerfind('Name','FebirdTimer');