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. MATLAB engine also converts incoming Python data into MATLAB data types.
Pass Data from MATLAB to Python
When you pass data from MATLAB to Python, either directly or as output from a MATLAB function in Python, MATLAB converts the data into the equivalent Python data types.
MATLAB Output Argument Type | Resulting Python Data Type |
---|---|
Numeric array |
|
|
|
Complex (any numeric type) |
|
|
|
|
|
|
|
|
|
|
|
|
|
string array (1-by-N or
N -by-1) |
|
|
|
cell array (1-by- |
|
|
|
|
|
|
|
|
|
table timetable |
|
|
|
MATLAB handle object (such as the
|
|
MATLAB value object (such as the |
|
Unsupported MATLAB Data Types
Along with the exceptions noted in the table, MATLAB does not convert these MATLAB data types to Python data types:
char
array (M
-by-N
)string
array (M
-by-N
)cell array (
M
-by-N
)Sparse array
struct
arrayObjects not produced by MATLAB (such as Java® objects)
Function handle
Pass Data from Python to MATLAB
When you pass data from Python to MATLAB, either directly or as input arguments to a MATLAB function in Python, the MATLAB engine converts the data into the equivalent MATLAB data types.
Python Data Type | Resulting MATLAB Data Type |
---|---|
| Numeric array |
Python objects that support the buffer protocol, such as
| Numeric array |
|
|
| Complex |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Python objects other than |
|
Unsupported Python Data Types
Along with the exceptions noted in the table, MATLAB does not convert these Python data types to MATLAB data types:
Python class (
module.type
) objectsNone
object