next up previous contents
Next: CUTEr and MEX-Files Up: Interfacing CUTEr and Matlab Previous: Interfacing CUTEr and Matlab   Contents

MEX-Files basics

Besides being a self-sufficient environment, Matlab provides an Application Program Interface (API) to support external user-defined subroutines. This interfacing is realized through dynamically-linked subroutines, compiled by Matlab from C or Fortran source code, referred to as MEX-Files. For a thorough exploration of MEX-Files accompanied by numerous examples and details, refer to your local Matlab documentation. Recall also that all API-related documentation is available online using the Matlab Help Desk. We now briefly review the main features of MEX-Files and what the user should provide for Matlab to be able to compile the interface.

Any user-provided C or Fortran computational routine may be interfaced with the Matlab environment using the mex script. Within Matlab, the mex command takes the name of the routine to be interfaced as an argument plus a number of options and possibly other files. Refer to the mex script documentation for a complete list of all supported options. For every routine the user wishes to interface with Matlab, a gateway routine must be provided in order to inform Matlab about the number of arguments that the computational routine takes and what their type is. This gateway routine calls the user-defined computational routine as a subroutine. The file resulting of the compilation and linking of these two routines is called a MEX-File. Assume your own Fortran routine qrFactor.f is to be interfaced with Matlab and that a gateway is provided in the file qrFactorg.f, Matlab compiles and links qrFactor.f once it is given the command matlab% mex qrFactor.f qrFactorg.f

Possibly, if several user-defined routines are to be compiled within Matlab, the gateway routine may interface them all at once. For details regarding the construction of a gateway, the reader is referred to the Matlab documentation.


next up previous contents
Next: CUTEr and MEX-Files Up: Interfacing CUTEr and Matlab Previous: Interfacing CUTEr and Matlab   Contents
Dominique Orban 2005-03-24