How to stop the running program through push a 'stop' button in appdesigner?
26 次查看(过去 30 天)
显示 更早的评论
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...
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172033/image.png)
0 个评论
采纳的回答
Wentao Du
2018-4-16
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 个评论
Pietro Prestininzi
2020-4-27
编辑:Pietro Prestininzi
2020-4-27
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
2020-10-30
编辑:Benjamin Jacot
2020-10-30
@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
更多回答(1 个)
Debt
2021-8-29
You can use the uiwait and uiresume Fcu to realize it,and you should konw their object is uifigure
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!