How to save output from a timer that callback a function
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
Mostafa
on 13 Oct 2016
Add a line to save the data to a .mat file (either create new mat file for each timestamp, or append all data to one .mat file). Load the data whenever needed.
Ilaria Di Fresco
on 14 Oct 2016
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)
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!