How do I jump out of an endless loop in App Designer?

4 ビュー (過去 30 日間)
Hieu Philip Hoang
Hieu Philip Hoang 2018 年 12 月 4 日
コメント済み: madhan ravi 2018 年 12 月 4 日
Hi!
I created 3 buttons with App Designer to control a stepper motor, where
Button 1: Moves forward
Button 2: Moves backward
Button 3: Stops everything
Now, I tried to realize it with an endless loop, so that if Button 1 is clicked, it will move forward endlessly. My callback functions for button 1 and 2 then look like this:
app.check = 1;
app.check = 0;
while app.check = 0
%some functions to move the motor
if app.check = 1
break
end
end
Here I set an app property app.check. This should be set to 1 whenever a push button is pressed to then jump out of a previous loop via the if line.
Now, as it is an endless loop, pressing the button won't change the value of app.check, as this task is only queued and won't be set until the endless loop ends.
And exactly this is my problem. Is there any other opportunity, to just let callback 1 run until something else is pressed?
Much regards and thank you for reading!

採用された回答

Geoff Hayes
Geoff Hayes 2018 年 12 月 4 日
編集済み: Geoff Hayes 2018 年 12 月 4 日
Hieu - try putting a drawnow or pause in your while loop so that it can be interruptible (which should allow the push button callback to execute and so change the state of the check variable).
  2 件のコメント
Hieu Philip Hoang
Hieu Philip Hoang 2018 年 12 月 4 日
Thank you very much! "drawnow" before the if works
madhan ravi
madhan ravi 2018 年 12 月 4 日
+1

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by