Main Content

Pass Data to MATLAB from Python

When you pass Python® data as input arguments to MATLAB® functions, the MATLAB Engine API for Python converts the data into equivalent MATLAB data types.

Python Type to MATLAB Scalar Type Mapping

This table shows how MATLAB converts incoming Python scalar data to MATLAB data types.

Python Input Argument Type —
Scalar Values Only

Resulting MATLAB Data Type

float

double

complex

Complex double

int

int64

float(nan)

NaN

float(inf)

Inf

bool

logical

str

char

dict

struct if all keys are strings
Not supported otherwise

matlab.dictionary

dictionary
MATLAB converts the data in a matlab.dictionary object using the mappings in this table, with the exception that str data is converted to string.

Python objects (other than dict) that support the mapping protocol

dictionary

Python Container to MATLAB Array Type Mapping

This tables shows how MATLAB converts incoming Python container data to MATLAB data types.

Python Input Argument Type —
Container

Resulting MATLAB Data Type

matlab numeric array object (see MATLAB Arrays as Python Variables)

Numeric array

bytearray

uint8 array

bytes

uint8 array

list

Cell array

set

Cell array

tuple

Cell array

Unsupported Python Types

The MATLAB Engine API does not support these Python types:

  • Python class (module.type) objects

  • None

Related Topics