| Contents | Index |
| On this page… |
|---|
The MATLAB engine library contains routines that allow you to call MATLAB software from your own programs, thereby employing MATLAB as a computation engine. You must use an installed version of MATLAB; you cannot run the MATLAB engine on a machine that only has the MATLAB Compiler Runtime (MCR).
Engine programs are standalone C/C++ or Fortran programs that communicate with a separate MATLAB process via pipes, on UNIX systems, and through a Microsoft Component Object Model (COM) interface, on Microsoft Windows systems. MATLAB provides a library of functions that allows you to start and end the MATLAB process, send data to and from MATLAB, and send commands to be processed in MATLAB.
Some of the things you can do with the MATLAB engine are:
Call a math routine, for example, to invert an array or to compute an FFT from your own program. When employed in this manner, MATLAB is a powerful and programmable mathematical subroutine library.
Build an entire system for a specific task, for example, radar signature analysis or gas chromatography, where the front end (GUI) is programmed in C/C++ and the back end (analysis) is programmed in MATLAB, which can shorten development time.
The MATLAB engine operates by running in the background as a separate process from your own program. This offers several advantages:
On UNIX systems, the engine can run on your machine, or on any other UNIX machine on your network, including machines of a different architecture. This allows you to implement a user interface on your workstation and perform the computations on a faster machine located elsewhere on your network. For more information, see the engOpen reference page.
Instead of requiring your program to link to the entire MATLAB program (a substantial amount of code), it links to a smaller engine library.
The MATLAB engine cannot read MAT-files in a format based on HDF5. These are MAT-files saved using the -v7.3 option of the save function or opened using the w7.3 mode argument to the C or Fortran matOpen function.
Note To run MATLAB engine on the UNIX platform, you must have the C shell csh installed at /bin/csh. |
To create an engine application, you need the tools and knowledge to modify and build source code in C/C++ or Fortran. In particular, you need a compiler supported by MATLAB. For an up-to-date list of supported compilers, see the Supported and Compatible Compilers Web page.
In your application, use functions in the MATLAB C/C++ and Fortran API:
To build the application, use the mex build script with the compiler-specific engine options file. For more information, see Compiling Engine Applications with the MEX Command. You can also use your own build tools, as described in Compiling Engine Applications in an IDE.
The engine library is part of the MATLAB C/C++ and Fortran API. It contains routines for controlling the computation engine. The function names begin with the three-letter prefix eng.
MATLAB libraries are not thread-safe. If you create multithreaded applications, make sure only one thread accesses the engine application.
C Engine Routines
| Function | Purpose |
|---|---|
Start up MATLAB engine | |
Shut down MATLAB engine | |
Get a MATLAB array from the engine | |
Send a MATLAB array to the engine | |
Execute a MATLAB command | |
Create a buffer to store MATLAB text output | |
Start a MATLAB engine session for single, nonshared use | |
Determine visibility of MATLAB engine session | |
Show or hide MATLAB engine session |
Fortran Engine Routines
| Function | Purpose |
|---|---|
Start up MATLAB engine | |
Shut down MATLAB engine | |
Get a MATLAB array from the engine | |
Send a MATLAB array to the engine | |
Execute a MATLAB command | |
Engine programs also use the MX Matrix Library in the C/C++ and Fortran API. For more information about this library, see Introducing MEX-Files.
On UNIX systems, the engine library communicates with the engine using pipes, and, if needed, rsh for remote execution. On Microsoft Windows systems, the engine library communicates with the engine using a Component Object Model (COM) interface. For more information, see Introducing MATLAB COM Integration.
If you have graphical user interface (GUI) intensive applications that execute a lot of callbacks through the MATLAB engine, you should force these callbacks to be evaluated in the context of the base workspace. Use evalin to specify that the base workspace be used in evaluating the callback expression, as follows:
engEvalString(ep, "evalin('base', expression)")Specifying the base workspace in this manner ensures MATLAB processes the callback correctly and returns results for that call.
This does not apply to computational applications that do not execute callbacks.
![]() | Calling MATLAB Engine from C/C++ and Fortran Programs | Examples of Calling Engine Functions | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |