External Interfaces/API | ![]() ![]() |
Although MATLAB® is a complete, self-contained environment for programming and manipulating data, it is often useful to interact with data and programs external to the MATLAB environment. MATLAB provides an interface to external programs written in the C and Fortran languages. This interface is part of the MATLAB Application Program Interface, or API.
This section discusses the following topics:
For additional information and support in building your applications, see the Additional Information section of this chapter.
Note
In platform independent discussions that refer to directory paths, this book uses the UNIX convention. For example, a general reference to the mex directory is <matlab>/extern/examples/mex .
|
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:
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.
![]() | External Interfaces/API | Using MEX-Files | ![]() |