Data Type Conversions Between MATLAB REST Function Services and Python
R2026bWhen you use a MATLAB® REST function service in your Python® application, the service converts between Python data types and MATLAB data types. For information on data type conversions in Python when calling MATLAB Engine API for Python, see Pass Data Between MATLAB and Python from Python.
Pass Data from Python to MATLAB
When you pass data from Python to MATLAB, the MATLAB REST function service 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
| This conversion is not supported directly. You must first convert
such types to a supported type, such as
matlab.double,
matlab.single, or one of the MATLAB integer types. |
|
|
| Complex |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Unsupported Python Data Types
Along with the exceptions noted in the table, the following conversions from Python data types to MATLAB data types are not supported.
datetime.datetimedatetime.timedeltaenumtypematlab.dictionarymatlab.objectNoneobjectnumpy.datetime64numpy.timedelta64pandas.DataFramePython objects other than
dictthat support the mapping protocol (such ascollections.OrderedDict)Python class (
module.type) objects
Pass Data from MATLAB to Python
When you pass data from MATLAB to 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- |
|
Unsupported MATLAB Data Types
The following conversions from MATLAB data types to Python data types are not supported.
chararray (M-by-N)stringarray (M-by-N)cell array (
M-by-N)Sparse array
structarraydatetimedurationdictionarytabletimetableObjects not produced by MATLAB (such as Java® objects)
Function handle
MATLAB handle object (such as the
containers.Maptype)MATLAB value object (such as the
categoricaltype)