External Interfaces/API |
Using MEX-Files
MEX-files are subroutines produced from C or Fortran source code. They behave just like M-files and built-in functions. While M-files have a platform-independent extension, .m
, MATLAB identifies MEX-files by platform-specific extensions. This table lists the platform-specific extensions for MEX-files.
Platform |
MEX-File Extension |
Alpha |
mexaxp |
HP, Version 10.20 |
mexhp7 |
HP, Version 11.x |
mexhpux |
IBM RS/6000 |
mexrs6 |
Linux |
mexglx |
SGI, SGI64 |
mexsg |
Solaris |
mexsol |
Windows |
dll |
You can call MEX-files exactly as you would call any M-function. For example, a MEX-file called conv2.mex
on your disk in the MATLAB datafun
toolbox directory performs a 2-D convolution of matrices. conv2.m
only contains the help text documentation. If you invoke the function conv2
from inside MATLAB, the interpreter looks through the list of directories on the MATLAB search path. It scans each directory looking for the first occurrence of a file named conv2
with the corresponding filename extension from the table or .m
. When it finds one, it loads the file and executes it. MEX-files take precedence over M-files when like-named files exist in the same directory. However, help text documentation is still read from the .m
file.
Introducing MEX-Files | The Distinction Between mx and mex Prefixes |