Handle manual breaks

2 views (last 30 days)
Darin
Darin on 27 Feb 2012
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

Answers (1)

Walter Roberson
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.
  1 Comment
Darin
Darin on 27 Feb 2012
Thanks! do you know of a good button function that will allow the code to continue, not waiting for its response?

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!