mexCallMATLAB (Fortran)
Call MATLAB function, user-defined function, or MEX file
Fortran Syntax
#include "fintrf.h" integer*4 mexCallMATLAB(nlhs, plhs, nrhs, prhs, functionName) integer*4 nlhs, nrhs mwPointer plhs(*), prhs(*) character*(*) functionName
Arguments
nlhsNumber of output arguments. Must be less than or equal to 50.
plhsArray of pointers to output arguments
Caution
The
plhsargument formexCallMATLABis not the same as theplhsformexFunction. Do not destroy anmxArrayreturned inplhsformexFunction.nrhsNumber of input arguments. Must be less than or equal to 50.
prhsArray of pointers to input arguments
functionNameCharacter string containing name of the MATLAB® built-in function, operator, user-defined function, or MEX function to call.
If
functionNameis an operator, place the operator inside a pair of single quotes, for example,'+'.
Returns
0 if successful, and a nonzero value if unsuccessful.
Description
Call mexCallMATLAB to invoke internal MATLAB numeric functions, MATLAB operators, user-defined functions, or other MEX files. Both
mexCallMATLAB and mexEvalString execute
MATLAB commands. Use mexCallMATLAB for returning results
(left side arguments) back to the MEX function. The mexEvalString function
does not return values to the MEX function.
For a complete description of the input and output arguments passed to
functionName, see mexFunction.
Error Handling
If functionName detects an error, MATLAB terminates the MEX file and returns control to the MATLAB prompt. To trap errors, use the mexCallMATLABWithTrap
function.
Limitations
Avoid using the
mexCallMATLABfunction in Simulink® S-functions. If you do, do not store the resultingplhsmxArraypointers in any S-function block state that persists after the MEX function finishes. Outputs ofmexCallMATLABhave temporary scope and are automatically destroyed at the end of the MEX function call.It is possible to generate an object of type
mxUNKNOWN_CLASSusingmexCallMATLAB. For example, this function returns two variables but only assigns one of them a value.function [a,b] = foo(c) a = 2*c;
If you then call
foousingmexCallMATLAB, the unassigned output variable is now typemxUNKNOWN_CLASS.
Examples
To open an example, type:
edit([fullfile(matlabroot,"extern","examples","refbook","filename")]);
where filename is:
To open an example, type:
edit([fullfile(matlabroot,"extern","examples","mx","filename")]);
where filename is:
Tips
MATLAB allocates dynamic memory to store the arrays in
plhsformexCallMATLAB. MATLAB automatically deallocates the dynamic memory when you exit the MEX file. However, if heap space is at a premium, callmxDestroyArraywhen you are finished with the arrays inplhs.
Version History
Introduced before R2006a
See Also
mexFunction | mexCallMATLABWithTrap | mexEvalString | mxDestroyArray