Main Content

Write Fortran Functions Callable fromMATLAB(MEX Files)

Write Fortran subroutines that can be called from MATLAB®

You can call your own Fortran subroutines from the MATLAB command line as if they were built-in functions. These programs are called MEX files, and the function name is the MEX file name.

To create a MEX file, write your programs using the MATLAB API libraries — Fortran MEX API and Fortran Matrix API. The functions in these libraries facilitate the transfer of data between MEX files and the workspace. For more information, seeFortran Source MEX Files. Then build the source file into an executable program using themexfunction. For more information, seeExecutable Fortran MEX Files.

If you have a Fortran program and want to call MATLAB functions, then use the engine library functions described inCall MATLAB from Fortran.

If you want to read and write MATLAB data from Fortran programs, then use the Fortran MAT-File API described inWrite Fortran Programs to Read MAT-File Data.

Categories