How to send Python list as a column vector in Matlab?

조회 수: 4 (최근 30일)
JHaazez
JHaazez 2016년 6월 3일
답변: Bo Li 2016년 6월 3일
Following the solution to this thread, https://www.mathworks.com/matlabcentral/answers/166188-can-i-call-my-own-custom-matlab-functions-from-python-r2014b I have been able to successfully reach personal MATLAB functions. The issue when calling these functions is that they expect MATLAB column vectors, but Python does not support this, Python uses lists. I tried using Python's numpy to create something that resembles the MATLAB column vector more than a Python list but the matlab.engine doesn't seem to support sending numpy arrays.
How can I send a Python list as a column vector?
Is the only way to have my MATLAB function's take the transpose of the Python list to form a column vector once I have already reached MATLAB?
Below is what I am trying to do.
import matlab.engine
eng = matlab.engine.start_matlab()
eng.addpath(r'c:\myPath', nargout=0)
testList = [0.50, 0.55, 0.60]
transposedTestList = eng.tranpose(testList) # here is where the issue is
output = myMatlabFunction(transposedTestList)

채택된 답변

Bo Li
Bo Li 2016년 6월 3일
Try MATLAB arrays for Python:
>>> testList=[0.5, 0.55, 0.6]
>>> testVector=matlab.double(testList)
>>> testColumnVector=eng.transpose(testVector)
>>> testVector.size
(1, 3)
>>> testColumnVector.size
(3, 1)
>>> l
Reference:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by