This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

MEX File Functions

Call C/C++ or Fortran MEX file functions from MATLAB®

A MEX file is a function, created in MATLAB, that calls a C, C++, or Fortran subroutine. To call a MEX file, use the name of the file, without the file extension. The MEX file contains only one function or subroutine, and its name is the MEX file name. The file must be on your MATLAB path.

For information about creating MEX files, see:

For information about using MEX S-functions in models, see your Simulink® documentation.


mexextBinary MEX file-name extension
inmemNames of functions, MEX-files, classes in memory


Using MEX Files

MEX functions are subroutines created from C/C++ or Fortran source code. They behave just like MATLAB scripts and built-in functions. 

MEX File Placement

Put your MEX file in a folder on the MATLAB path.

Run MEX File You Receive from Someone Else

How to run a MEX file.


Version Compatibility

For best results, run MEX files built with your MATLAB version.

Platform Compatibility

If you get a binary MEX file from another source, be sure that the file was compiled for the same platform on which you want to run it.

Invalid MEX File Errors

What to do when you get an invalid MEX file error.