toggle button to stop a for loop not working

I am trying to exit a for loop using toggle button, created using guide. Toggle button is initially called 'Run'. The iteration starts when 'Run' is hit and the toggle button string changes to 'Stop'. However, iteration continues after 'Stop' is hit (in the screenshot, 'Stop' is hit at i=2). I used dbstack to check the Run callbacks. Am I missing something obvious?? Any help would be appreciated. Here's the code snippet and the command window screenshot-

 採用された回答

Image Analyst
Image Analyst 2016 年 12 月 19 日

0 投票

I don't have time to debug your code tonight, but you can try my demo of basically the same thing. attached.

1 件のコメント

Disha
Disha 2016 年 12 月 19 日
編集済み: Disha 2016 年 12 月 19 日
Thank you very much Image Analyst.
Thank you Geoff Hayes (concerning another post mentioned below)
The part I was missing was to check the value of the hObject inside the for loop. This is due to the fact that multiple calls to callback function are stacked and executed subsequently (nicely explained here - https://in.mathworks.com/matlabcentral/answers/162797-how-to-continue-from-same-line-using-toggle-button-gui ). As I did not check the updated property of hObject inside the for loop, after the second callback to the toggle button finished, the first callback continued without reflecting the updated hObject value. Here's the modified code snippet -

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

質問済み:

2016 年 12 月 19 日

編集済み:

2016 年 12 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by