How to stop the running program through push a 'stop' button in appdesigner?
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
NAN ZHANG
el 11 de Abr. de 2018
Respondida: Debt
el 29 de Ag. de 2021
I am trying to design a interface using appdesigner.I want to know how to pause the running program when i push the 'stop' button,and when i push it again, the program continue to run. How am i supposed to do? And i also want to know how to stop the running program by code. I have tried 'pause()' 'dbcont' 'dbquit' ,such functions. They do not work.... Sorry for my bad english...
0 comentarios
Respuesta aceptada
Wentao Du
el 16 de Abr. de 2018
A workaround would be to check for a change in a condition. This change would be caused by the a push-button callback or a checkbox selection. That is, it would reflect that the user would like to stop/pause/resume execution.
If you would like to pause execution and then resume execution from the same point, you would have to break down your code into multiple sections. Each section will be identified by a certain number. When the pause condition is met at a certain point, the workspace data will be saved into a MAT file and a value will be returned by the PAUSE_FUNC function which is executed when the pause condition is met.
When you click the Resume button, a function is executed which tells the computer where to resume execution of the code from. This function will have as input the variable returned by PAUSE_FUNC. This allows the program to recognize where execution was stopped. The previously saved data will be loaded again and execution can resume from where it was paused.
To stop execution, simply exit the function when the condition value is changed accordingly.
4 comentarios
Pietro Prestininzi
el 27 de Abr. de 2020
Editada: Pietro Prestininzi
el 27 de Abr. de 2020
Hi,
I cannot implement Wentao's suggestion:
I have a button that sets
app.stopiter=false
and then calls a procedure conained in a .m file which contains a while loop.
i=0;
while i<app.numiter && app.stopiter==false
i=i+1
...
end
The app has a "STOP" button that sets
app.stopiter=true;
but has no effect on the while loop....unless you are running it in debug mode....
what am i doing wrong?
Benjamin Jacot
el 30 de Oct. de 2020
Editada: Benjamin Jacot
el 30 de Oct. de 2020
@Pietro Prestininzi: I have the same problem with a for loop and an If statement that stop the loop
for k = Vector
if app.stopiter
break
end
...
end
It is working in debug mode only. But I found a trick to solve it; I added a short pause before checking the condition.
for k = Vector
pause(1e-4)
if app.stopiter
break
end
...
end
Más respuestas (1)
Debt
el 29 de Ag. de 2021
You can use the uiwait and uiresume Fcu to realize it,and you should konw their object is uifigure
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!