timer doesn't work
显示 更早的评论
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
采纳的回答
更多回答(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
2023-2-20
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 个评论
Walter Roberson
2023-2-20
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
2023-2-20
Walter Roberson
2023-2-20
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
2023-2-21
Walter Roberson
2023-2-21
Store the code in a file and execute the file.
roberto
2023-2-21
roberto
2023-2-21
Walter Roberson
2023-2-21
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
2023-2-21
No there is not.
类别
在 帮助中心 和 File Exchange 中查找有关 Downloads 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!