How to save output from a timer that callback a function
이전 댓글 표시
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
Mostafa
2016년 10월 13일
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
2016년 10월 14일
raym
2018년 3월 4일
in the function ,first get(obj,'UserData'), then combine with the new output set(obj,'UserData',[get(obj,'UserData'),output]);
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!