Return multiple variables from MATLAB to Python
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello,
I am using MATLAB for data processing and Python for Keras + TensorFlow. I must say that I am new to Python, but I am confortable coding in MATLAB.
I have a function in MATLAB which return 3 matrices and has the following signature:
function [noisyMFCC, targetIBM, targetIRM] = getTestingData(sampleTesting)
While in Python I wrote this:
import matlab.engine
class DataProcessor:
__matlabEngine = matlab.engine.start_matlab()
def getTestingData(self, isSampleTesting):
return DataProcessor.__matlabEngine.getTestingData(isSampleTesting)
def getTrainingData(self, isSampleTesting):
return DataProcessor.__matlabEngine.getTrainingData(isSampleTesting)
dp = DataProcessor()
a, b, c = dp.getTestingData(True)
print(a)
And I receive the following error:
ValueError: too many values to unpack (expected 3)
So I assume that MATLAB engine returns some kind of structure or just one of the three returns.
a, b, c = dp.getTestingData(True, nargout=3)
And it returns (as expected):
TypeError: getTestingData() got an unexpected keyword argument 'nargout'
Apperently if I am to use the following line of code:
c = dp.getTestingData(True, nargout=3)
c is the first return element of the function, how do I get the rest?
Thank you for your time!
댓글 수: 0
채택된 답변
Bo Li
2017년 2월 6일
Apparently, "nargout" is a keyword argument defined for Python Engine. "dp.getTestingData(True, nargout=3)" does not work because the member function "getTestingData" of "class DataProcessor" does not accept this keyword argument. You can specify the number of output when calling Python Engine:
def getTestingData(self, isSampleTesting):
return DataProcessor.__matlabEngine.getTestingData(isSampleTesting, nargout=3)
댓글 수: 0
추가 답변 (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!