External Interfaces/API    

Calling Functions from Fortran MEX-Files

It's possible to call MATLAB functions, operators, M-files, and even other MEX-files from within your Fortran source code by using the API function mexCallMATLAB. This example creates an mxArray, passes various pointers to a subfunction to acquire data, and calls mexCallMATLAB to calculate the sine function and plot the results.

This is the subroutine that sincall calls to fill the mxArray with data.

It is possible to use mexCallMATLAB (or any other API routine) from within your computational Fortran subroutine. Note that you can only call most MATLAB functions with double-precision data. M-functions that perform computations, like eig, will not work correctly with data that is not double precision.

Running this example

displays the results


The following example creates an M-file that returns two variables but only assigns one of them a value.

MATLAB displays the following warning message.

If you then call foo using mexCallMATLAB, the unassigned output variable will now be of type mxUNKNOWN_CLASS.


  Handling Sparse Matrices Advanced Topics