Main Content

处理从 MATLAB 返回到 Python 的数据

MATLAB 标量类型到 Python 类型的映射

当 MATLAB® 函数返回输出参量时,MATLAB Engine API for Python® 会将数据转换为等同的 Python 数据类型。

MATLAB 输入参量类型 -
仅标量值

生成的 Python 数据类型

double

float

single

float

复数(任意数值类型)

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

string 中的 <missing>

None

char

str

结构体

dict

MATLAB 句柄对象(例如 containers.Map 类型)

matlab.object

MATLAB 返回对 matlab.object 的引用,而不是返回对象本身。您不能在 MATLAB 会话之间传递 matlab.object

MATLAB 值对象(例如 categorical 类型)

不透明对象。您可以将值对象传递给 MATLAB 函数,但不能创建或修改它。

MATLAB 数组类型到 Python 类型的映射

MATLAB 输出参量类型 -
数组

生成的 Python 数据类型

数值数组

matlab 数值数组对象(请参阅 MATLAB 数组作为 Python 变量

string 向量

strlist

char 数组(1×NN×1)

str

行或列元胞数组

list

不支持的 MATLAB 类型

MATLAB Engine API for Python 不支持以下 MATLAB 数据类型。

  • char 数组(M×N

  • 元胞数组(M×N

  • 稀疏数组

  • 结构体数组

  • 非 MATLAB 对象(例如 Java® 对象)

相关主题