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.
I also tried a solution given by here :
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!

采纳的回答

Bo Li
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 个)

类别

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