Return multiple variables from MATLAB to Python

9 vues (au cours des 30 derniers jours)
Petru-Daniel Tudosiu
Petru-Daniel Tudosiu le 5 Fév 2017
Réponse apportée : Bo Li le 6 Fév 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!

Réponse acceptée

Bo Li
Bo Li le 6 Fév 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)

Plus de réponses (0)

Catégories

En savoir plus sur Call MATLAB from Python dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by