Main Content

Pass Data Between MATLAB and Python

Pass Data from MATLAB to Python

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

MATLAB Output Argument Type
(scalar unless otherwise noted)

Resulting Python Data Type

Numeric array

matlab numeric array object (see matlab Python Module)

double, single

float

Complex (any numeric type)

complex

int8, uint8, int16, uint16, int32

int

uint32, int64, uint64

int

NaN

float ('nan')

Inf

float ('inf')

logical

bool

char array (1-by-N or N-by-1)
char array (M-by-N)

str
Not supported

structure

dict

cell array (1-by-N or N-by-1)
cell array (M-by-N)

str
Not supported

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.

Other object (for example, Java® object)Not supported

Function handle

Not supported

Sparse array

Not supported

string array (1-by-N or N-by-1)
string array (M-by-N)

list
Not supported

Structure array

Not supported

Pass Data from Python to MATLAB

When you pass data as input arguments to MATLAB functions from Python, MATLAB converts the data into equivalent MATLAB data types.

Python Input Argument Type

Resulting MATLAB Data Type
(scalar unless otherwise noted)

matlab numeric array object (see matlab Python Module)

Numeric array

float

double

complex

Complex double

int

int32(Windows®)

int64(Linux® and Mac)

float('nan')

NaN

float('inf')

Inf

bool

logical

str

char

bytearray

uint8 array

bytes

uint8 array

dict

Structure if all keys are strings. Not supported otherwise

list

Cell array

set

Cell array

tuple

Cell array

memoryview

Not supported

range

Cell array

None

Not supported

module.type

Not supported

Related Topics