What are the Python types accepted by MATLAB?

7 次查看(过去 30 天)
I tried the following, using both MATLAB R2017b and R2017a from Python 2.7 IDLE:
>>> import numpy as np
>>> image = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 2.0]], dtype="uint8")
>>> image
array([[1, 0, 0],
[0, 1, 2]], dtype=uint8)
>>> g = eng.mean(image)
However, I received the following error:
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
g = eng.mean(image)
File "C:\Python27\lib\site-packages\matlab\engine\matlabengine.py", line 73, in __call__
out=_stdout, err=_stderr)
TypeError: unsupported Python data type: numpy.ndarray
Does it mean that non built-in Python types (such as NumPy) are not supported by MATLAB?

采纳的回答

MathWorks Support Team

The MATLAB interoperability features only support built-in Python types. For instance, NumPy arrays are not part of core Python and therefore they are not recognized in MATLAB.

Nevertheless, for many applications of non-built-in Python types, the MATLAB equivalent can be used. For instance, if you want to use a NumPy array, you can directly create a MATLAB Array in Python. Please find below the MATLAB documentation for it, which contains some examples about how to create multidimensional arrays as well:

https://www.mathworks.com/help/matlab/matlab_external/matlab-arrays-as-python-variables.html

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

产品


版本

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by