User`s manual
C MEX-Files
2-5
Required Arguments to a MEX-File
The two components of the MEX-file may be separate or combined. In either 
case, the files must contain the 
#include "mex.h" header so that the entry 
point and interface routines are declared properly. The name of the gateway 
routine must always be 
mexFunction and must contain these parameters.
void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
/* more C code ... */
The parameters nlhs and nrhs contain the number of left- and right-hand 
arguments with which the MEX-file is invoked. In the syntax of the MATLAB 
language, functions have the general form
[a,b,c,…] = fun(d,e,f,…)
where the ellipsis (…) denotes additional terms of the same format. The a,b,c,… 
are left-hand arguments and the 
d,e,f,… are right-hand arguments.
The parameters 
plhs and prhs are vectors that contain pointers to the left- and 
right-hand arguments of the MEX-file. Note that both are declared as 
containing type 
mxArray *, which means that the variables pointed at are 
MATLAB arrays. 
prhs is a length nrhs array of pointers to the right-hand side 
inputs to the MEX-file, and 
plhs is a length nlhs array that will contain 
pointers to the left-hand side outputs that your function generates.










