Can I use a GUI button to kill running routines?
Show older comments
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)
Walter Roberson
on 10 Jan 2012
0 votes
The only ways to kill a routine without its active cooperation are very ugly.
2 Comments
John
on 10 Jan 2012
Walter Roberson
on 11 Jan 2012
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.
Jan
on 10 Jan 2012
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
Find more on Startup and Shutdown 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!