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 Create MATLAB Arrays in Python)

double
single

float

Complex (any numeric type)

complex

int8
uint8
int16
uint16
int32

int

uint32
int64
uint64

int
long

NaN

float('nan')

Inf

float('inf')

logical

bool

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

str
Not supported

structure

dict

Row or column cell array

list

M-by-N cell arrayNot supported

MATLAB handle object (table, containers.Map, categorical array)

Not supported

Other object (e.g., Java®)Not supported

Function handle

Not supported

Sparse array

Not supported

String arrayNot 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 Create MATLAB Arrays in Python)

Numeric array

float

double

complex

Complex double

int

int32(Windows®)

int64(Linux® and Mac)

long [a]

int64

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

[a] long is a data type of Python 2.7 only

Related Topics