This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Call MATLAB Functions from Fortran MEX Files

You can call MATLAB® functions, operators, user-defined functions, and other binary MEX files from within your Fortran source code by using the API function mexCallMATLAB. The sincall.F example creates an mxArray, passes various pointers to a local function to acquire data, and calls mexCallMATLAB to calculate the sine function and plot the results. To see the source code, open the file in MATLAB Editor. fill.F is the subroutine sincall calls to fill the mxArray with data. (Open the file in MATLAB Editor.)

It is possible to use mexCallMATLAB (or any other API routine) from within your computational Fortran subroutine. You can only call most MATLAB functions with double-precision data. Some functions that perform computations, such as the eig function, do not work correctly with data that is not double precision.

To build this example, at the command prompt type:

mex sincall.F fill.F

Running this example:


displays the results:

    Note:   You can generate an object of type mxUNKNOWN_CLASS using mexCallMATLAB. See the following example.

This function returns two variables but only assigns one of them a value:

function [a,b]=foo[c]

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

Was this topic helpful?