Friday, May 8, 2009

What is a MATLAB mex file?

A mex file is a matlab source type file
that allows the user to compile partial code
as C/C++ code. MATLAB runs an interpreter
for running the code. Since code interpretation
is usually slower as compared to running
pre-compiled binaries on a machine, MATLAB
provides an approach to do this by using the
built in mcc tool.

These mex files define certain entry points
in a standard matlab code where, a function
call is translated to a C/C++ code and later
accept values from the computed results.
Such an approach finds a lot of application with
compute intensive operations such as graph
search or image recognition which can be done
better with optimized C code.


Dave Smith said...

Note that these files can be written as REX files (remotely executable) or as DLLs. REX files are usually faster since they run on 32 bit codes.

Post a Comment