Using MEX-Files to Call C/C++ and Fortran Programs

From ift
Revision as of 15:14, 10 January 2011 by Gge002 (talk | contribs) (Created the page, waiting for an add-on that can display source code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Understanding MEX

MEX-files (MATLAB executables) are used to call large pre-existing C/C++ and Fortran programs from MATLAB without translating them into MATLAB. Another advantage is that C/C++ code is generally faster than MATLAB.

The best source of information is MathWorks' knowledge database.

To understand C/C++ Source MEX-Files see:

To understand how to use MEX-Files to Call C/C++ and Fortran Programs see

Tips 'n' Tricks

  1. Where to place the gateway routine within the C/C++ program - it looks like the gateway routine should be the last routine in the code. This sheds the problem with undefined variables and alike. I (GG) haven't found any place in the knowledge base where this is mentioned. Maybe it is not true in all cases either. Here follows an example that is a modification of the original MATLAB code from the knowledge database (see link "MEX-Files to Call C/C++ and Fortran Programs" above). In the case below three input parameters are required, while in the original code only two are necessary. A comparison between the two version helps to find the in-s and out-s.