- you could, each iteration, store variables in a data structure or file, along with an indication of how much of the data structure has been completely written to, and then after you control-C you could execute a function to extract the most recently complete information out of what is saved
- you could create a toggle button or other kind of control, whose callback destroys the control. Then inside your loop, each iteration you can check whether the control still exists, and if so then leave the loop.
- you could create a toggle button uitogglebutton just before your loop. Then inside your loop, each iteration you can check to see whether the button has been clicked, and if so then leave the loop. If you do this it is a good idea to first check whether the control still exists, in case the user x'd to close the control instead of just clicking the button
- you could create a KeyPressFcn callback for a figure, and have the callback change some setting that you can test inside the loop
How can I stop manually a true while loop?
3 ビュー (過去 30 日間)
古いコメントを表示
Eduardo Gabriel González Blancas
2022 年 11 月 20 日
回答済み: Walter Roberson
2022 年 11 月 20 日
I'm using the a true While loop to get some data from arduino because I can leave it there collecting information without a specific time or iterations, but I want to stop it manually when I decide it's enough (I tried to use a Ctrl + C, but that clear all the data I mean my function doesn't return any value).
0 件のコメント
採用された回答
Walter Roberson
2022 年 11 月 20 日
Pressing control-C will interrupt a calculation, and there is no way to catch control-C to handle it smoothly.
0 件のコメント
その他の回答 (1 件)
the cyclist
2022 年 11 月 20 日
When a file is executing, the Run button in the editor window becomes a Pause button. Pressing that will pause execution, with access to the variables.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で MATLAB Support Package for Arduino Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!