Main Content

Handle Data Returned from MATLAB to Python

MATLAB Scalar Type to Python Type Mapping

When MATLAB® functions return output arguments, 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

int64

int

uint64

int

NaN

float(nan)

Inf

float(inf)

logical

bool

string

str

<missing> value in string

None

char

str

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 str

char array (1-by-N, N-by-1)

str

Row or column cell array

list

Unsupported MATLAB Types

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