Stop the function pause(n)

Hi everybody,
i've a question about pause(n) where n is the time in seconds.
The fragment code where i've the problem is this:
tic
while (~get(handles.pause,'Value')) %toc<=60 &&
writePosition(s,maxTravel);
pause(ts);
writePosition(s,INITPOS);
pause(ts);
cycle = cycle+1;
cycleTotal(day+1) = cycle+1;
[time,minutes,hours,day] = timerFun(minutes,hours,day,toc);
set(handles.status,'String',time);
pause(ttot);
end
in fact i use the 'Value' of ToggleButton, named pause, to stop the while cycle, but the pause(ttot) varies (i.e. 1 second or 20 seconds), obviously if the waiting time is short the ToggleButton 'Value' is checked frequently, otherwise if the waiting time is long when i push the ToggleButton on the GUI i must wait the end of pause before the while-cycle 'Value' is invoked.
Is there a trick to stop pause() function or other method to check the ToggleButton 'Value' independently from pause function?

3 comentarios

Geoff Hayes
Geoff Hayes el 13 de Oct. de 2016
Niccolò - how does the ttot value vary since it is never assigned a value once the while loop starts? I don't think that you can cancel the pause once it has started...
Niccolò de Cesare
Niccolò de Cesare el 13 de Oct. de 2016
Sorry,
I've omitted pre and post code at cycle. This piece of code is into a GUI and user, through a text box, sets the delay and start the process with a button. As I said the delay varies and thus the togglebutton check is slow if the pause(ttot) is long. If ttot=20, for example and I press togglebutton when the pause is just started I must wait 20 seconds before the check happen, therefore I'm interested to know if there's a way to stop the pause function or to make a togglebutton check in other manner.
Tonghui Zhang
Tonghui Zhang el 24 de Mayo de 2019
Hi,
I am confronted with this problem now. When I quit GUI, the pause function is still working. I am wondering if there is any method to terminate it when the GUI is close(except ctrl+c)?
Thanks in advance

Iniciar sesión para comentar.

Respuestas (1)

Geoff Hayes
Geoff Hayes el 27 de Mayo de 2019

0 votos

Rather than using a while loop in your GUI code, use a timer which you can then programmatically start and stop. See https://www.mathworks.com/matlabcentral/answers/284202-how-to-plot-a-real-time-signal-with-axes-automatically-updating for one such example.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Oct. de 2016

Respondida:

el 27 de Mayo de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by