How to stop (an infinite loop) / the execution of my matlab code via app designer?

109 ビュー (過去 30 日間)
Hey, i got an infinite while loop in my script and i want to get out of it using matlab app.designer, therefore i created a start button to run my script which is working perfectly fine and a stop button to stop it whenever the user wants to from the designer.
I couldnt figure how to programme the stop button. a solution can be the change of the value of the while loop(while true ==> while false) from the designer when clicking on the stop button. how can i do it?
i appreciate every help and thanks in advance!
  3 件のコメント
Matlab_Beginner
Matlab_Beginner 2022 年 8 月 30 日
Hey, i did not actually. i saw the link its almost the same question as mine. i will try it and tell u
Thanks
Matlab_Beginner
Matlab_Beginner 2022 年 8 月 30 日
Hey again, i didnt figure out what to put in the ButtonCallback fnct. i quit new to app designer, can u provide me with more info on how to do it.
thanks a lot.

サインインしてコメントする。

採用された回答

Ankit
Ankit 2022 年 8 月 30 日
@Matlab_Beginner Please find solution to your problem, I have attached *.mlapp file too
  1 件のコメント
Matlab_Beginner
Matlab_Beginner 2022 年 8 月 30 日
編集済み: Matlab_Beginner 2022 年 8 月 30 日
Edit: it works perfect! thanks a lot

サインインしてコメントする。

その他の回答 (1 件)

Rik
Rik 2022 年 8 月 30 日
You need to use the callback function from your stop button to edit a value. This is the general structure:
function StartButtonCallback(app)
app.StopButtonClicked=false;
while ~app.StopButtonClicked
% Do things
% Process any callbacks in the queue. This will also update the value
% of app.StopButtonClicked if the stop button callback has run.
drawnow
end
end
function StopButtonCallback(app)
app.StopButtonClicked=true;
end
  3 件のコメント
Image Analyst
Image Analyst 2022 年 8 月 30 日
Evidently you also have a function called "StopButtonPushed" which is not shown in your screenshot. Don't have the flag name be the same as your callback function name. Call the flag StopButtonClicked like he said, not StopButtonPushed (which is your function's callback name).
Matlab_Beginner
Matlab_Beginner 2022 年 8 月 30 日
i get it,thanks a lot :))

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by