Call MATLAB from Python - MATLAB & Simulink (original) (raw)
Main Content
Write Python® programs that work with MATLAB®
Functions
Classes
Topics
Installing
- Install MATLAB Engine API for Python
MATLAB Engine API for Python allows you to call MATLAB functions and execute MATLAB commands from within a Python environment. To use the MATLAB engine, you must have a supported version of Python installed on your machine, and you must install MATLAB Engine API for Python as a Python package.
Getting Started
- Get Started with MATLAB Engine API for Python
MATLAB Engine API for Python provides a Python package namedmatlab
that enables you to call MATLAB functions from Python. - Start and Stop MATLAB Engine for Python
Options for starting the MATLAB Engine for Python. - Call MATLAB Functions from Python
How to return an output argument from a MATLAB function. How to read multiple outputs from a function. What to do when the MATLAB function does not return an output argument. - Get Help for MATLAB Functions from Python
From Python, you can access supporting documentation for all MATLAB functions.
Data Exchange and Mapping
- Use MATLAB Arrays in Python
This example shows how to create a MATLAB array in Python and pass it as the input argument to the MATLABsqrt
function. - MATLAB Arrays as Python Variables
Thematlab
Python module provides array classes to represent arrays of MATLAB numeric types as Python variables so that MATLAB arrays can be passed between Python and MATLAB. - Pass Data Between MATLAB and Python
When you return MATLAB data to Python, MATLAB Engine API for Python converts the data into the equivalent Python data type. - Use MATLAB Handle Objects in Python
This example shows how to create an object from a MATLAB handle class and call its methods in Python. - Default Numeric Types in MATLAB and Python
By default, a number in MATLAB has a double-precision type. - Use MATLAB Dictionaries in Python
MATLAB Engine API for Python converts a Pythondict
to a MATLAB dictionary and a MATLAB dictionary to a Pythondict
. - Use MATLAB Tables and Timetables in Python
Convert between MATLAB tables and timetables and Python pandas DataFrames. - How MATLAB Handles Datetime and Duration Types in Python
Convert between MATLABdatetime
andduration
values and Pythondatetime
andnumpy
types.
Calling MATLAB Functions
- Call User Scripts and Functions from Python
This example shows how to call a MATLAB script to compute the area of a triangle from Python. - Sort and Plot MATLAB Data from Python
This example shows how to sort data about patients into lists of smokers and nonsmokers in Python and plot blood pressure readings for the patients with MATLAB. - Call MATLAB Functions Asynchronously from Python
This example shows how to call the MATLABsqrt
function asynchronously from Python and retrieve the square root later. - Redirect Standard Output and Error to Python
This example shows how to redirect standard output and standard error from a MATLAB function to PythonStringIO
objects.