MATLAB Application Program Interface
  Go to function:
    Search    Help Desk 
mexCallMATLAB    Examples   See Also

Call a MATLAB function, or a user-defined M-file or MEX-file

C Syntax

Arguments

nlhs
  Number of desired output arguments. This value must be less than or equal to 50.

plhs
  Pointer to an array of mxArrays. The called command puts pointers to the resultant mxArrays into plhs. Note that the called command allocates dynamic memory to store the resultant mxArrays. By default, MATLAB automatically deallocates this dynamic memory when you clear the MEX-file. However, if heap space is at a premium, you may want to call mxDestroyArray as soon as you are finished with the mxArrays that plhs points to.

nrhs
  Number of input arguments. This value must be less than or equal to 50.

prhs
  Pointer to an array of input arguments.

command_name
  Character string containing the name of the MATLAB built-in, operator, M-file, or MEX-file that you are calling. If command_name is an operator, just 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, M-files, or other MEX-files. See mexFunction for a complete description of the arguments.

By default, if command_name detects an error, MATLAB terminates the MEX-file and returns control to the MATLAB prompt. If you want a different error behavior, turn on the trap flag by calling mexSetTrapFlag.

Note that it is possible to generate an object of type mxUNKNOWN_CLASS using mexCallMATLAB. For example, if you create an M-file that returns two variables but only assigns one of them a value,

you'll get this warning message in MATLAB:

MATLAB assigns output b to an empty matrix. If you then call foo using mexCallMATLAB, the unassigned output variable will now be of type mxUNKNOWN_CLASS.

Examples

Create a populated mxArray and call mexCallMATLAB to display its contents. Then, call mexCallMATLAB a second time to calculate the eigenvalues and eigenvectors of the newly created mxArray. Finally, call mexCallMATLAB a third time to display the eigenvalues.

For an additional example, see mexcallmatlab.c in the mex subdirectory of the examples directory.

See Also

mexFunction, mexSetTrapFlag



[ Previous | Help Desk | Next ]