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.

Handle Data Returned from MATLAB to Python

MATLAB Scalar Type to Python Type Mapping

When MATLAB® functions return output arguments, the MATLAB Engine API for Python® converts the data into equivalent Python data types.

MATLAB Output Argument Type —
Scalar Values Only

Resulting Python Data Type

double

float

single

float

Complex (any numeric type)

complex

int8

int

uint8

int

int16

int

uint16

int

int32

int

uint32

int (Python 3.x)
long (Python 2.7)

int64

int (Python 3.x)
long (Python 2.7)

uint64

int (Python 3.x)
long (Python 2.7)

NaN

float(nan)

Inf

float(inf)

logical

bool

char returned to Python 3.x

str

char returned to Python 2.7

str (when MATLAB char value is less than or equal to 127)
unicode (when MATLAB char value is greater than 127)

Structure

dict

MATLAB handle object (such as the containers.Map type)

matlab.object

MATLAB returns a reference to a matlab.object, not the object itself. You cannot pass a matlab.object between MATLAB sessions.

MATLAB Array Type to Python Type Mapping

MATLAB Output Argument Type —
Array

Resulting Python Data Type

Numeric array

matlab numeric array object (see MATLAB Arrays as Python Variables)

char array (1-by-N, N-by-1) returned to Python 3.x

str

char array (1-by-N, N-by-1) returned to Python 2.7

str (when MATLAB char array has values less than or equal to 127)
unicode (when MATLAB char array has any value greater than 127)

Row or column cell array

list

Unsupported MATLAB Types

The MATLAB Engine API for Python does not support these MATLAB data types.

  • Categorical array

  • char array (M-by-N)

  • Cell array (M-by-N)

  • Function handle

  • Sparse array

  • Structure array

  • Table

  • MATLAB value objects (for a discussion of handle and value classes see Comparison of Handle and Value Classes)

  • Non-MATLAB objects (such as Java® objects)

Related Topics