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!