MATLAB Application Program Interface | Search  Help Desk |
mexFunction |
MATLAB entry point to a Fortran MEX-file
subroutine mexFunction(nlhs, plhs, nrhs, prhs) integer*4 nlhs, nrhs, plhs(*), prhs(*)nlhs
mexFunction
.
mexFunction is not a routine you call. Rather, mexFunction is the name of a subroutine you must write in every MEX-file. When you invoke a MEX-file, MATLAB searches for a subroutine named mexFunction inside the MEX-file. If it finds one, then the first executable line in mexFunction becomes the starting point of the MEX-file. If MATLAB cannot find a subroutine named mexFunction inside the MEX-file, MATLAB issues an error message.
When you invoke a MEX-file, MATLAB automatically loads nlhs
, plhs
, nrhs
, and prhs
with the caller's information. In the 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. The a,b,c
are left-hand side arguments and the d,e,f
are right-hand side arguments. The arguments nlhs
and nrhs
contain the number of left-hand side and right-hand side arguments, respectively, with which the MEX-function is called. prhs
is an array of mxArray
pointers whose length is nrhs
. plhs
is a pointer to an array whose length is nlhs
, where your function must set pointers for the returned left-hand side mxArrays
.