How to convert data types in Python to mlarray?
조회 수: 4 (최근 30일)
이전 댓글 표시
import matlab.engine
eng = matlab.engine.start_matlab()
# mlarray to ndarray: np.asarray(x._data, dtype=dtype)
c = eng.magic(5)
print(type(c))
d = np.asarray(c)
print(type(d))
# ndarray to mlarray:?????
a = np.random.random(10)
a1 = a.tolist()
a2 = eng.cell(a1)
a3 = eng.cellfun(@double,a2,'UniformOutput',false)
print(type(a1))
print(type(a2))
print(type(a3))
SyntaxError: invalid syntax
How to convert data types in Python to mlarray?
댓글 수: 0
답변 (1개)
rakshit gupta
2023년 6월 6일
To convert a ndarray to a mlarray in Python using MATLAB Engine, you can use the 'matlab.double()' function.
Here's an example of how you can convert an ndarray to mlarray:
import matlab.engine
import numpy as np
eng = matlab.engine.start_matlab()
# create an ndarray
a = np.random.random(10)
# convert ndarray to mlarray
mla = matlab.double(a.tolist())
# verify that the mlarray was created
print(type(mla))
# pass the mlarray to a MATLAB function, for example, to calculate the sum
result = eng.sum(mla)
# print the result
print(result)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!