Interrupt a timer wait function
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Robert Dylans
am 6 Okt. 2015
Beantwortet: Walter Roberson
am 6 Okt. 2015
I have a function that runs through an undetermined amount of iterations in 5 second intervals, until a user clicks the "cancel" button to stop it. For this button, I'm currently using the 'waitbar' function, and creating a cancel button ('canceling') on it.
progress=waitbar(0,'1','Name','Logging Data...','CreateCancelBtn','setappdata(gcbf,''canceling'',1)');
setappdata(progress,'canceling',0);
looping=getappdata(progress,'canceling');n=1;
while looping==0
n=n+1;
t=timer('TimerFcn',@(~,~)waitbar(0,progress,n),'StartDelay',5);
start(t)
%Functions%
wait(t);
looping=getappdata(progress,'canceling');
end
delete(progress)
While this is technically working, the check for the cancel button happens after the 5 second delay. This means after clicking cancel, the popup will remain up until the delay ends.
My question is, is there some type of interrupt function that can be used to stop a timer immediately? Or any other type of function that would yield the same result?
Many thanks!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 6 Okt. 2015
Do not create and start the timer every iteration and wait for it: create and start it once with an indefinite repeat. Have the cancel callback stop() the timer.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dialog Boxes finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!