Introducing MEX Files

You can call your own C, C++, or Fortran subroutines from the MATLAB® command line as if they were built-in functions. These programs, called binary MEX files, are dynamically linked subroutines that the MATLAB interpreter loads and executes. The MEX file contains only one function or subroutine, and its name is the MEX file name. To call a MEX file, use the name of the file, without the file extension.

For information about using a MEX function that someone else created, see MEX File Functions.

The term mex stands for “MATLAB executable” and has different meanings, as shown in the following table.

MEX TermDefinition
source MEX fileC, C++, or Fortran source code file.
binary MEX file or MEX functionDynamically linked subroutine executed in the MATLAB environment.
MEX function libraryMATLAB C and Fortran API Reference library to perform operations in the MATLAB environment.
mex build scriptMATLAB function to create a binary file from a source file.

Related Examples

More About