CMEX-files

CMEX files in general have the following components:

All CMEX-files must include the following statement:
 
#include "mex.h"
mex.h is a header file that declares the entry point and interface routines.

 

The computational routine:
This is a regular C function that performs a certain computation and returns its outputs to the gateway routine, that passes it out to MATLAB.

 

The gateway routine:
This interfaces MATLAB with the C computational routine by the entry-point mexFunction and its parameters:

prhs: pointer to right-hand-side (i.e, pointer to input matrix)
plhs: pointer to left-hand-side (i.e, pointer to output matrix)
nrhs: number of right-hand-side arguments (i.e, number of inputs)
nlhs: number of left-hand-side arguments (i.e, number of outputs)
void mexFunction(int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ]) { /* stuff */ }

 


Please refer to page 3-4 of the API manual: Figure 3-1: C MEX Cycle

Back to Table of Contents