Why MEX?
There are several situations where you might want to use a MEX-file:
-
MEX-files interface large pre-existing C or Fortran code with MATLAB without rewriting the code in MATLAB.
-
The algorithm to be implemented contains some for or while loops that can not be vectorized.
MATLAB may not process loops as quickly as C or Fortran code. MEX-file loops run at normal
C or Fortran code speed, resulting in a substantial performance increase.
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 C or Fortran. In general, most programming should be done in MATLAB. Do not use the MEX facility unless your application requires it.
Back to Table of Contents