User`s manual
2 Creating C Language MEX-Files
2-6
For example, if you invoke a MEX-file from the MATLAB workspace with the
command
x = fun(y,z);
the MATLAB interpreter calls mexFunction with the arguments
plhs is a 1-element C array where the single element is a null pointer. prhs is
a 2-element C array where the first element is a pointer to an
mxArray named
Y and the second element is a pointer to an mxArray named Z.
The parameter
plhs points at nothing because the output x is not created until
the subroutine executes. It is the responsibility of the gateway routine to create
an output array and to set a pointer to that array in
plhs[0]. If plhs[0] is left
unassigned, MATLAB prints a warning message stating that no output has
been assigned.
Note It is possible to return an output value even if nlhs = 0. This
corresponds to returning the result in the ans variable.
nlhs = 1
nrhs = 2
plhs
prhs
•
Ø
•
Y
•
Z