Run MEX File You Receive from Someone Else

To call a MEX file, put the file on your MATLAB® path. Then type the name of the file, without the file extension.

If you have MEX file source code, see Build C MEX Function for information about creating the executable function.

If you get run-time errors when you call a MEX file that you did not create, consider the following:

  • MEX Platform Compatibility

  • MEX Version Compatibility

  • On Windows® platforms, install the C++ compiler run-time libraries used to create the MEX file. This step is needed if you do not have the same compiler installed on your machine that was used to compile the MEX file.

  • If the MEX file uses specialized run-time libraries, then those libraries must be installed on your system.

If you write a MEX file, build it, and then execute it in the same MATLAB session, all the dependent libraries are available, as expected. However, if you receive a MEX file from another MATLAB user, you might not have all the dependent libraries.

A MEX file is a dynamically linked subroutine that the MATLAB interpreter loads and executes when you call the function. Dynamic linking means that when you call the function, the program looks for dependent libraries. MEX files use MATLAB run-time libraries and language-specific libraries. A MEX file might also use specialized run-time libraries. The code for these libraries is not included in the MEX file; the libraries must be present on your computer when you run the MEX file.

For troubleshooting library dependencies, see Invalid MEX File Errors.

For information about how MATLAB finds a MEX file, see Files and Folders that MATLAB Accesses.