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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
T
Tenable Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
W
WeLiveSecurity
D
DataBreaches.Net
Attack and Defense Labs
Attack and Defense Labs
H
Heimdal Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
AI
AI
P
Proofpoint News Feed
PCI Perspectives
PCI Perspectives
Schneier on Security
Schneier on Security
T
Threatpost
GbyAI
GbyAI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Help Net Security
F
Full Disclosure
T
Threat Research - Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
M
MIT News - Artificial intelligence
L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
Y
Y Combinator Blog
腾讯CDC
The Hacker News
The Hacker News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园_首页
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 最新话题
Security Latest
Security Latest
Know Your Adversary
Know Your Adversary
Forbes - Security
Forbes - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
SegmentFault 最新的问题
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
LangChain Blog
Vercel News
Vercel News
Cisco Talos Blog
Cisco Talos Blog
量子位
P
Proofpoint News Feed
H
Hacker News: Front Page
Help Net Security
Help Net Security
L
LINUX DO - 热门话题
Project Zero
Project Zero
C
Cisco Blogs

博客园 - 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');