This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

MATLAB Engine API for C

Write C/C++ programs that work with MATLAB®

Note

Functions in the Engine API for C work with the MATLAB mxArray data structure, which is defined in the C Matrix API. To write applications using C++11 features, see MATLAB Engine API for C++.

Engine applications are standalone programs that allow you to call MATLAB from your own C/C++ programs, using MATLAB as a computation engine. Engine applications require an installed version of MATLAB; you cannot run the MATLAB engine on a machine that only has the MATLAB Runtime.

C/C++ Engine API Functions

EngineType for MATLAB engine
engOpenStart MATLAB engine session
engOpenSingleUseStart MATLAB engine session for single, nonshared use
engCloseQuit MATLAB engine session
engEvalStringEvaluate expression in string
engGetVariableCopy variable from MATLAB engine workspace
engPutVariablePut variable into MATLAB engine workspace
engGetVisibleDetermine visibility of MATLAB engine session
engSetVisibleShow or hide MATLAB engine session
engOutputBufferSpecify buffer for MATLAB output

Functions

mexBuild MEX function from C/C++ or Fortran source code

Topics

Write Engine Applications

Getting Started

What you need to start building C or Fortran engine applications.

Introducing MATLAB Engine API 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 application engdemo.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 the Path environment variable.

Build Windows Engine Application

This example shows how to verify the build process on Windows® platforms using the C example engwindemo.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. If you run older versions, the registered version could change.

Build and Run Mac Applications

Set Run-Time Library Path on Mac Systems

Tell the operating system where the API shared libraries are by setting the DYLD_LIBRARY_PATH environment variable.

Build macOS Engine Application

This example shows how to verify the build process on a macOS platform.

Run macOS Engine Application

This example shows how to run the C example engdemo.c from the Mac 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 the LD_LIBRARY_PATH environment variable.

Build Linux Engine Application

This example shows how to verify the build process on a Linux® platform.

Run Linux Engine Application

This example shows how to run the C example engdemo.c from the Linux system prompt.

Build in Integrated Development Environment

Build Engine Applications with IDE

Tips to configure your integrated development environment to build engine applications.

Troubleshooting

Can't Start MATLAB Engine

What to do when MATLAB engine does not run.

Debug MATLAB Function Called by C Engine

How to verify MATLAB functions used in engine applications.

User Input Not Supported

Some MATLAB functions that interact with the user are not supported in engine applications.

Multithreaded Applications

MATLAB libraries are not thread-safe.