How to stop the running program through push a 'stop' button in appdesigner?

129 views (last 30 days)
NAN ZHANG
NAN ZHANG on 11 Apr 2018
Answered: Debt on 29 Aug 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...

Accepted Answer

Wentao Du
Wentao Du on 16 Apr 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 Comments
Benjamin Jacot
Benjamin Jacot on 30 Oct 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

Sign in to comment.

More Answers (1)

Debt
Debt on 29 Aug 2021
You can use the uiwait and uiresume Fcu to realize it,and you should konw their object is uifigure

Community Treasure Hunt

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

Start Hunting!