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, int16, int32, int64
uint8, uint16, uint32, 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

struct scalar
struct array

dict
not supported

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

str
Not supported

dictionary

matlab.dictionary

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 scalar
string array (1-by-N or N-by-1)
string array (M-by-N)

str
list
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

int64

float('nan')

NaN

float('inf')

Inf

bool

logical

str

char

bytearray

uint8 array

bytes

uint8 array

dict

struct

matlab.dictionary

dictionary

list

Cell array

set

Cell array

tuple

Cell array

Objects that support the buffer protocol, such as memoryview, array.array, or NumPy ndarray

Numeric array

None

Not supported

module.type

Not supported

Related Topics