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-file that someone else created, see Call 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-fileDynamically linked subroutine executed in the MATLAB environment.
MEX function libraryMATLAB C/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

Was this topic helpful?