如何在Matlab中使用Timer [英] How to use Timer in Matlab
问题描述
我想使用Matlab从Yahoo获得IBM价格价格可以得到
I want use matlab to get IBM price from yahoo price can get by
quote = fetch(yahoo, 'IBM', 'Last');
px = quote.Last;
现在,我想每分钟从例如上午9:00到下午1:00检索数据.我想使用计时器对象来获取数据.
Now I want to retrieve the data every minute from, for example, 9:00 am to 1:00 pm. I would like to use timer object to get my data.
但是,我不知道如何使用它.我能得到的是
However, I cannot figure out how to use it. What I can get is
t = timer;
t.ExecutionMode = 'fixedRate';
t.Period = 60;
尤其是 timerFcn
,我不知道如何使用它.
especially the timerFcn
, I don't get how to use it.
希望有人可以为此写一个例子.谢谢
Hope someone can write me an example with this. Thanks
推荐答案
需要写一个回调函数才能使用TimerFcn
.
You need to write a callback function to use TimerFcn
.
让它成为您的主文件,您可以在其中启动计时器:
Let this be your main file, where you initiate the timer:
tmr = timer('ExecutionMode', 'FixedRate', ...
'Period', 60, ...
'TimerFcn', {@timerCallback});
start(tmr);
这将是您的回调函数,它将在每次计时器计数完成时执行(例如,在您的示例中,每60秒执行一次).
Then this would be your callback function, which would execute every time the timer count is complete (i.e. every 60 seconds in your example).
function timerCallback(hObj, eventdata)
disp('timey-wimey');
end
这篇关于如何在Matlab中使用Timer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!