Return multiple variables from MATLAB to Python

6 Ansichten (letzte 30 Tage)
Petru-Daniel Tudosiu
Petru-Daniel Tudosiu am 5 Feb. 2017
Beantwortet: Bo Li am 6 Feb. 2017
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!

Akzeptierte Antwort

Bo Li
Bo Li am 6 Feb. 2017
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)

Weitere Antworten (0)

Kategorien

Mehr zu Call MATLAB from Python finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by