Jay
Jay

Reputation: 117

How to use Timer in 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

Upvotes: 3

Views: 16931

Answers (1)

HebeleHododo
HebeleHododo

Reputation: 3640

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

Upvotes: 7

Related Questions