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

조회 수: 30 (최근 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...

채택된 답변

Wentao Du
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
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
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
Debt 2021년 8월 29일
You can use the uiwait and uiresume Fcu to realize it,and you should konw their object is uifigure

카테고리

Help CenterFile Exchange에서 环境和设置에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!