Write Fortran Functions Callable from MATLAB (MEX Files)
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, see Fortran Source MEX Files. Then build the source file into an executable program using the
mex function. For more information, see Executable Fortran MEX Files.
If you have a Fortran program and want to call MATLAB functions, then use the engine library functions described in Call MATLAB from Fortran.
If you want to read and write MATLAB data from Fortran programs, then use the Fortran MAT-File API described in Write Fortran Programs to Read MAT-File Data.