Main Content

Call MATLAB from Python

Write Python® programs that work with MATLAB®

The MATLAB Engine API for Python provides a package for Python to call MATLAB as a computational engine. The engine supports the reference implementation (CPython). For supported version information, see Versions of Python Compatible with MATLAB Products by Release.

Engine applications require an installed version of MATLAB; you cannot run the MATLAB engine on a machine that only has the MATLAB Runtime.

Functions

expand all

matlab.engine.start_matlabStart MATLAB Engine for Python
matlab.engine.find_matlabFind shared MATLAB sessions to connect to MATLAB Engine for Python
matlab.engine.connect_matlabConnect shared MATLAB session to MATLAB Engine for Python
matlab.engine.shareEngineConvert running MATLAB session to shared session
matlab.engine.engineNameReturn name of shared MATLAB session
matlab.engine.isEngineSharedDetermine if MATLAB session is shared

Classes

expand all

matlab.engine.MatlabEnginePython object using MATLAB as computational engine within Python session
matlab.engine.FutureResultResults of asynchronous call to MATLAB function stored in Python object

Topics

Installing

Getting Started

Session Management

Using MATLAB Workspace

Data Exchange and Mapping

Calling MATLAB Functions

Troubleshooting

Limitations to MATLAB Engine API for Python

The MATLAB Engine API does not support these features.

Troubleshoot MATLAB Errors in Python

When a MATLAB function raises an error, the MATLAB Engine for Python stops the function and catches the exception raised by MATLAB.