- 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?
조회 수: 4(최근 30일)
Eduardo Gabriel González Blancas 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).
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.