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

string

string

<missing> value in string

None

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 value object (such as the categorical type)

Opaque object. You can pass a value object to a MATLAB function but you cannot create or modify it.

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)

string vector

list of string

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.

  • char array (M-by-N)

  • Cell array (M-by-N)

  • Sparse array

  • Structure array

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

Related Topics