Can I use a GUI button to kill running routines?

I'm looking for a callback command to give to an "Exit" button in a GUI that will not only close the window ('close' is being used now), but will also kill the routine without closing MATLAB. Does such a command exist, or do I need a more complex set of instructions for the "Exit" button?

Answers (2)

The only ways to kill a routine without its active cooperation are very ugly.

2 Comments

Bummer. Do you know where can I get a look at these ugly ways?
Someone mentioned a way in passing, in the newsgroup, sometime in the last 5 years.
Let's see... you could call a mex routine that deliberately corrupted the memory allocation scheme, so that eventually the executing routine would crash.

Sign in to comment.

The easiest way would be to let the function check, if the GUI is still open. What ever you do, the function needs to be cooperative anyway: Without a DRAWNOW the "Exit" button events are not processed. Then you can append a small check also:
drawnow;
if ishandle(CallerGUI) == 0
% Cleanup! Close files etc.
return;
end
You cannot use the Java-robot to simulate a Ctrl-C, because this would even kill the function, which controls the robot. But from a C-mex function an ugly injection of Ctrl-C should work, see: FEX: textinject. I have never tried it and I will not. Killing a function without a proper cleanup is too ugly.

Categories

Tags

Asked:

on 10 Jan 2012

Community Treasure Hunt

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

Start Hunting!