f



softly interrupting a MATLAB function

Does anyone know if there is a way to interrupt a long-running MATLAB
function in such a way that one can execute a separate set of
commands in a "catch"-type environment? Basically, I'd like to
combine Cntl-C with error trapping, so that Cntl-C executes a catch
block (i.e., try-catch-end), since it doesn't occur naturally.

I have done something similar to this in a GUI environment, but in
this case, it is in batch mode.

Thanks,
Mark
0
8/4/2006 4:23:58 PM
comp.soft-sys.matlab 211266 articles. 19 followers. lunamoonmoon (257) is leader. Post Follow

3 Replies
919 Views

Similar Articles

[PageSpeed] 12

Mark Abramson wrote:
> Does anyone know if there is a way to interrupt a long-running MATLAB
> function in such a way that one can execute a separate set of
> commands in a "catch"-type environment? Basically, I'd like to
> combine Cntl-C with error trapping, so that Cntl-C executes a catch
> block (i.e., try-catch-end), since it doesn't occur naturally.
> 
> I have done something similar to this in a GUI environment, but in
> this case, it is in batch mode.
> 
> Thanks,
> Mark

unfortunately you can't catch signals in matlab functions (something TMW 
should really consider to implement...).

the poor-mans solution (for me at least) is to periodically check for 
the existence of a certain file (call it e.g. ABORT). if it's not there, 
continue, else abort. easy as that :-)


michael
0
mwild (177)
8/5/2006 8:19:26 AM
> commands in a "catch"-type environment? Basically, I'd like to
> combine Cntl-C with error trapping, so that Cntl-C executes a catch
> block (i.e., try-catch-end), since it doesn't occur naturally.
>

Try this:

 <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=7840&objectType=file>

warning i don't know if it works,- I haven't tried it.
0
rek1 (97)
8/5/2006 9:34:16 AM
The closest I have been able to get to this is writing MEX functions
which disable/enable control-C interrupts. This only works in
Unix/Linux:

/* Turn control-C off */
#include "mex.h"
#include <signal.h>

void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray
*prhs[])
{
  sighold(SIGINT);
}

/* Turn control-C back on */
#include "mex.h"
#include <signal.h>

void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray
*prhs[])
{
  sigrelse(SIGINT);
}
0
yegulalp (1)
8/17/2006 9:45:36 AM
Reply: