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!