Using MEX-Files

Binary MEX-files are subroutines produced from C/C++ or Fortran source code. They behave just like MATLAB® scripts and built-in functions. While scripts have a platform-independent extension .m, MATLAB identifies MEX-files by platform-specific extensions. The following table lists the platform-specific extensions for MEX-files.

PlatformBinary MEX-File Extension

Linux® (64-bit)


Apple Mac (64-bit)


Microsoft® Windows® (32-bit)


Windows (64-bit)


You call MEX-files exactly as you call any MATLAB function. For example, on a Windows platform, there is a binary MEX-file called histc.mexw32 (in the MATLAB toolbox folder matlabroot\toolbox\matlab\datafun) that performs a histogram count. The file histc.m contains the help text documentation. When you call histc from MATLAB, the dispatcher looks through the list of folders on the MATLAB search path. It scans each folder looking for the first occurrence of a file named histc with either the corresponding file name extension from the table or .m. When it finds one, it loads the file and executes it. Binary MEX-files take precedence over .m files when like-named files exist in the same folder. However, help text documentation still reads from the .m file.

You cannot use a binary MEX-file on a platform if you compiled it on a different platform. Recompile the source code on the platform for which you want to use the MEX-file.

Was this topic helpful?