User`s manual

Introducing MEX-Files
1-3
Introducing MEX-Files
You can call your own C or Fortran subroutines from MATLAB as if they were
built-in functions. MATLAB callable C and Fortran programs are referred to
as MEX-files. MEX-files are dynamically linked subroutines that the MATLAB
interpreter can automatically load and execute.
MEX-files have several applications:
Large pre-existing C and Fortran programs can be called from MATLAB
without having to be rewritten as M-files.
Bottleneck computations (usually
for-loops) that do not run fast enough in
MATLAB can be recoded in C or Fortran for efficiency.
MEX-files are not appropriate for all applications. MATLAB is a
high-productivity system whose specialty is eliminating time-consuming,
low-level programming in compiled languages like Fortran or C. In general,
most programming should be done in MATLAB. Don’t use the MEX facility
unless your application requires it.
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 1-1: MEX-File Extensions
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