|
Dear All,
Does anyone know how I can detect the use of CTRL-C in a Matlab callback
function when it is executed by a C++ MEX file?
Many thanks,
Chris.
P.S. Here is some code that demonstrates the problem. In Matlab R2008b,
this program continue to print the numbers up to 24, even if CTRL-C is
pressed. That also corrupts the Matlab command window.
// Compile with: mex CtrlCExample.cpp
// Run as: CtrlCExample(@pause)
// matlab mex includes
#include "mex.h"
#include "matrix.h"
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
long count = 0;
mxArray* pRhsNew[1];
pRhsNew[0] = mxDuplicateArray(prhs[0]);
while(1)
{
if (mexCallMATLAB(0, NULL, 1, pRhsNew, "feval"))
{
mexErrMsgTxt("Error evaluating callback function!");
return;
};
mexPrintf("Count = %d\n",count++);
if (count == 25)
{
return;
}
}
mexPrintf("END\n\n");
return;
}
|