Http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/mexfunction.htmlmexFunction (C and Fortran )-
Entry point to C/C ++ or Fortran Mex-File
C syntax
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[]);
FORTRAN
Syntax
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
integer*4 nlhs, nrhs
mwPointer plhs(*), prhs(*)
Arguments
-
Nlhs
-
Number
Of expected outputMxarray
S
-
Plhs
-
Array
Of pointers to the expected outputMxarray
S
-
Nrhs
-
Number
Of inputMxarray
S
-
Prhs
-
Array of pointers to
InputMxarray
S.
Do not modify anyPrhs
Values in your Mex-file.
Changing the data in these read-onlyMxarray
S can
Produce undesired side effects.
Description
Mexico Function
Is not a routine you call.
Rather,Mexico Function
Is the name of the Gateway
Function in C (subroutine in FORTRAN) which every Mex-file requires.
When you invoke a Mex-function, Matlab software finds and Loads
The corresponding Mex-file of the same name. MATLAB then searches
For a symbol namedMexico Function
Within the Mex-file.
If it finds one, It callthe Mex-function using the address ofMexico Function
Symbol. MATLAB displays
An error message if it cannot find a routine namedMexico Function
Inside
The Mex-file.
When you invoke a Mex-file, Matlab automatically
SeedsNlhs
,Plhs
,Nrhs
,
AndPrhs
With the caller's information. In
Syntax of the MATLAB language, functions have the general form:
[a,b,c,...] = fun(d,e,f,...)
Where
The...
Denotes more items of the same
Format.A, B, c...
Are left-hand side arguments,
AndD, e, f...
Are right-hand side arguments.
The argumentsNlhs
AndNrhs
Contain
The number of left-hand side and right-hand side arguments,
Respectively.Prhs
Is
An arrayMxarray
Pointers whose length isNrhs
.Plhs
Is
An array whose length isNlhs
, Where your function
Must set pointers for the returned left-hand sideMxarray
S.
Examples
See
Following examples inMATLAB Root
/Extern/examples/MEX
.