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

推荐订阅源

H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
L
LangChain Blog
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
G
Google Developers Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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