regarding the "Calling from MATLAB from Python" interface: how would I convert back array data returned from a matlab function as matlab.double()

I would like to refer to the example in the documentation, https://de.mathworks.com/help/matlab/matlab_external/use-matlab-arrays-in-python.html.
In the example the engine returns b, which is a 1-by-5 matlab.double array.
To further process / use that result in python it might be necessary to convert it back to a python list.
Is there a better way to do this than the following, which might be inefficient and complicated for large multidimensional arrays?
b_py = [v for v in b[0]]

 채택된 답변

Try
b._data
it should be much faster.

댓글 수: 3

I tend to not use properties / methods marked as private (leading underscore) - you never know when this breaks.
That's always a good practice. However, until someone in Mathworks solve this issue, i'm not familar with more efficent way that doesn't include passing through Lists.
To transfer info the other way(and not waiting couple of minutes for a simple 3d array), I had to write even nastier piece of code :o
So then your answer is it for the time being. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2020년 1월 24일

댓글:

2020년 5월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by