Immediatly break out from a loop upon callback

1 回表示 (過去 30 日間)
Théo
Théo 2020 年 5 月 16 日
コメント済み: Théo 2020 年 5 月 18 日
Hello,
Is it possible to immediatly break out from a loop upon callback, meaning without waiting the loop to finish the commands its doing?
For example, I have a GUI with a button giving Button.Value=0 or 1 if pressed or not
My code is structured like this:
while someconditions
%doAction1
pause(60)
%doAction2
pause(60)
end
But if I do:
while someconditions && Button.Value==1
%doAction1
pause(60)
%doAction2
pause(60)
end
or
while someconditions &&
if Button.Value==1
%doAction1
else
break
end
pause(60)
if Button.Value==1
%doAction2
else
break
end
pause(60)
end
then pressing the Button will not immediatly stop the loop but rather finish all the commands, including long pauses. For example, if I press the button in the middle of a pause, then I will have to wait before the loop breaks.
Sorry to bother but I searched extensively and didnt really find something.
I'm using Matlab2019b with the AppDesigner.
Thanks !
  2 件のコメント
Rik
Rik 2020 年 5 月 16 日
This is fundamental to how Matlab works: even user interactions shouldn't break things. If you absolutely have to stop execution right now, you can always use ctrl+c.
Théo
Théo 2020 年 5 月 18 日
Thank you for your answer.
I will rethink my algorithm then !

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by