Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Timer in Matlab

Tags:

matlab

I want use matlab to get IBM price from yahoo price can get by

quote = fetch(yahoo, 'IBM', 'Last');
px = quote.Last;

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;

especially the timerFcn, I don't get how to use it.

Hope someone can write me an example with this. Thanks

like image 432
Jay Avatar asked Nov 28 '25 10:11

Jay


1 Answers

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);

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
like image 55
HebeleHododo Avatar answered Dec 01 '25 08:12

HebeleHododo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!