I’ve looked through the documentation, etc, but I’m not seeing anything obvious. I’d like to have a signal handler that can intercept ^C, ^\, or some other keypress that could be used to interrupt a long-running script (each discrete computation is typically <1s) and allow it to exit gracefully and save current state.
Matlab does have event handlers for COM, but it’s windows-only and I’m in a *nix environment.
If the answer is ‘tough luck’, I’m cool with that … I’m just not seeing anything that says I’m SOL yet.
MATLAB already interprets
^Cas an interrupt. You can useonCleanupobjects to ensure that your program state is preserved correctly. I.e. something like:Run the above and hit
^Cwhen you get bored. Obviously, you can hook any function handle in to youronCleanupobject. See also the reference page for onCleanup.