Handle manual breaks

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

Risposte (1)

Walter Roberson
Walter Roberson il 27 Feb 2012

0 voti

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 Commento

Darin
Darin il 27 Feb 2012
Thanks! do you know of a good button function that will allow the code to continue, not waiting for its response?

Accedi per commentare.

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Richiesto:

il 27 Feb 2012

Community Treasure Hunt

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

Start Hunting!

Translated by