timer doesn't work
Show older comments
hello everybody,with this timer I wonder why stops and don't carry on to execute. what's wrong? I want webread to be refreshed every 60 secs. tks
t = timer('TimerFcn', 'stat=false; disp(''Timer!'')',...
'StartDelay',60);
start(t)
stat=true;
while(stat==true)
webread('https://www..etc...');
pause(1)
end
Accepted Answer
More Answers (3)
Here it shows that it is working. An alternative way is to use [tic .. toc] to count time if this is the objective:
Tspan = 10; % Time span 10 seconds
t = timer('TimerFcn', 'stat=false; disp(''Timer!'')', 'StartDelay',Tspan);
start(t)
tic
stat=true;
while(stat==true)
webread('https://www.mathworks.com');
pause(1)
end
Tend = toc;
fprintf('Total time with [tic...toc]: %f \n', Tend)
Sulaymon Eshkabilov
on 20 Feb 2023
Here is how it can be attained:
Tspan = 240; % Time span 240 seconds
t = timer('TimerFcn', 'stat=false; disp(''Timer!'')', 'StartDelay', Tspan);
start(t)
Tupdated = 60;
tic
stat=true;
ii = 0;
while(stat==true)
ii=ii+1;
fprintf('WEB is read for %d time \n', ii);
DT={webread('https://www.mathworks.com')};
pause(Tupdated)
end
Tend = toc;
fprintf('Total time with [tic...toc]: %f \n', Tend)
12 Comments
Walter Roberson
on 20 Feb 2023
If you are going to run a timer, have the invoked function do the webread. Timer period 60, and you can set a TasksToExecute if you want a limited period.
roberto
on 20 Feb 2023
Walter Roberson
on 20 Feb 2023
URL = 'https://www.mathworks.com'; %adjust as appropriate
t = timer('TimerFcn', @(src,event)do_timer_stuff(src,event,URL), 'Period', 60, 'ExecutionMode', 'fixedspacing');
start(t)
function do_timer_stuff(src, event, URL)
DT = webread(URL);
%now do something with the data you read
end
roberto
on 21 Feb 2023
Walter Roberson
on 21 Feb 2023
Store the code in a file and execute the file.
roberto
on 21 Feb 2023
roberto
on 21 Feb 2023
Walter Roberson
on 21 Feb 2023
https://www.mathworks.com/help/matlab/matlab_prog/share-data-between-workspaces.html
But remember you are configuring the timer to run indefinitely. You could store each result in a cell array, but your code is going to continue executing after you start() the timer. There is nothing that is sitting around waiting for new content to be added to the cell.
If what you want is to continually display the current content of the page then you should do that work inside the timer callback function.
Walter Roberson
on 21 Feb 2023
No there is not.
1 Comment
Categories
Find more on Downloads 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!