- 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?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Eduardo Gabriel González Blancas
le 20 Nov 2022
Réponse apportée : Walter Roberson
le 20 Nov 2022
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 commentaires
Réponse acceptée
Walter Roberson
le 20 Nov 2022
Pressing control-C will interrupt a calculation, and there is no way to catch control-C to handle it smoothly.
0 commentaires
Plus de réponses (1)
the cyclist
le 20 Nov 2022
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 commentaires
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!