Handle manual breaks
2 views (last 30 days)
Show older comments
Hi All,
I'm not sure if this is possible, but has anyone come across a way to handle manual breaks in code? i.e. if you Ctrl+C out of a loop, can you make the code respond to that?
An alternative would be making a popup button that you could press to stop the code, and then have the code do other things once you hit the button, but that seems like it might require 2 threads, one to make and monitor the button while the other executes code.
Thanks for any advice
0 Comments
Answers (1)
Walter Roberson
on 27 Feb 2012
control-C can never be caught.
The button approach doesn't really require two threads in any meaningful way. The code doing the work would have to occasionally have drawnow() or figure() or pause() calls in order to give a chance for the user interface to act on accumulated events; when it does so, it interrupts the active code, runs the callback and returns to the existing code. The callback can set a variable whose value is checked in the main code, with the main code voluntarily quiting when it sees that value.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!