How to save output from a timer that callback a function
8 views (last 30 days)
Show older comments
At the moment, I am working with a timer, which should run a function every half an hour. I am facing several troubles in saving the data generated by the function. The aim of my function (timerCallback) is to read some data from a website and record them into a vector called 'output'. Here is my function:
function [output,b,vars]=timerCallback(obj,event,fullURL)
fullURL = ['http://realtimeweb-prod.nationalgrid.com/SystemData.aspx'];
str = urlread(fullURL);
expression = '<span id="ContentPlaceHolder1_lblScoEng">(.*)</span>MW';
[tokens,matches] = regexp(str,expression,'tokens','match');
p=str2double(tokens{1}{1});
c=clock;
output=[c(1:5),p];
set(obj,'UserData',output);
end
I'd like to callback this function each half an hour and record the new data in a matrix, in order to have an history of this data.
Here I define my timer:
t=timer('TimerFcn',{@timerCallback},...
'ExecutionMode','fixedRate',...
'TasksToExecute',Inf);
The timer works, the command
set(obj,'UserData',output);
works as well, so the UserData of the timer is updated every time.
What I am not able to do is to save this updated result in my Workspace (and then, as final step, to build the matrix with all the recorded data).
If I use the command:
get(obj,'UserData')
I am only able to get the latest data recorded. I think that I need to write a code able to repeat this command every time that the timer run the function.
Any suggestions are more than welcome.
Ilaria
3 Comments
raym
on 4 Mar 2018
in the function ,first get(obj,'UserData'), then combine with the new output set(obj,'UserData',[get(obj,'UserData'),output]);
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!