Thread Subject: CTRL-C in MEX

Subject: CTRL-C in MEX

From: Chris Rodgers

Date: 3 Nov, 2009 22:08:12

Message: 1 of 1

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;
}

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com