Call MATLAB from C - MATLAB & Simulink (original) (raw)
Main Content
Run MATLAB® code from C programs, using mxArray
Note
Functions in the Engine API for C work with the MATLABmxArray data structure, which is defined in the C Matrix API. To write applications using modern C++ features, see Call MATLAB from C++.
Engine applications are standalone programs that allow you to call MATLAB from your own C/C++ programs, using MATLAB as a computation engine. To build an engine application, call themex function.
Engine applications require an installed version of MATLAB; you cannot run the MATLAB engine on a machine that only has the MATLAB Runtime.
Engine API for C
Topics
Write Engine Applications
- Create C Engine Applications Using mxArray
What to do to start building C engine applications. - MATLAB Engine APIs for C and Fortran
Call MATLAB from your own C and Fortran programs, using MATLAB as a computation engine. - Call MATLAB Functions from C Applications
Create a C engine applicationengdemo.c
. - Attach to Existing MATLAB Sessions
This example shows how to attach an engine program to a MATLAB session that is already running. - Callbacks in Applications
Design user interface callbacks to be evaluated in the context of the base workspace.
Build and Run Windows Applications
- Set Run-Time Library Path on Windows Systems
At run time, tell the operating system where the API shared libraries are by setting thePath
environment variable. - Build Windows Engine Application
This example shows how to verify the build process on Windows® platforms using the C exampleengwindemo.c
. - Run Windows Engine Application
This example shows how to run the C example,engwindemo.c
, from the Windows system prompt. - Register MATLAB as a COM Server
Register MATLAB for every session, to ensure that the current version of MATLAB is the registered version.
Build and Run Mac Applications
- Set Run-Time Library Path on macOS Systems
Tell the operating system where the API shared libraries are by setting theDYLD_LIBRARY_PATH
environment variable. - Build Engine Application on macOS
This example shows how to verify the build process on a macOS platform. - Run Engine Application on macOS
This example shows how to run the C exampleengdemo.c
from the macOS Terminal Window.
Build and Run Linux Applications
- Set Run-Time Library Path on Linux Systems
Tell the operating system where the API shared libraries are by setting theLD_LIBRARY_PATH
environment variable. - Build Engine Application on Linux
This example shows how to verify the build process on a Linux® platform. - Run Engine Application on Linux
This example shows how to run the C exampleengdemo.c
from the Linux system prompt.