External Interfaces Previous page   Next Page

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.

Table 3-1: MEX-File Extensions  
Platform
MEX-File Extension
HP-UX
mexhpux
Linux
mexglx
Macintosh
mexmac
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.


Previous page  Introducing MEX-Files MEX-File Placement Next page

© 1994-2005 The MathWorks, Inc.