I have a function in a MATLAB algorithm which uses the function sum. As described in the doc, the input of that function must be one of these types:
- Vector
- Matrix
- Multidimentionnal array
I know there are functions and doc on the MATLAB website to convert those datatypes. The problem is that I do not have the permission to modify the algorithm, only what I am sending it to. Is there a way to make the appropriate changes in python rather than taking the python data in MATLAB an making the data type changes?
For now, I have tried to use the MATLAB functions from the engine into python directly. I'm not sure that the conversion works properly.
Here is a MWE of my problem:
import matlab
import matlab.engine
myEngine = matlab.engine.start_matlab()
pythonData = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
pythonData = myEngine.cellstr(pythonData)
print('after cellstr()', pythonData)
pythonData = myEngine.cell2mat(pythonData)
print('after cell2mat()', pythonData)
matlabSum = myEngine.sum(pythonData)
print('sum:', matlabSum)
Here is the output on my terminal.
You will notice that cellstr didn't do much, which is weird. Does anyone have an idea on how to properly make those conversion? Also, the sum is not 477. It sould be 45. I'm pretty sure it is because it converts it into ASCII, which would result in [49,50,51,...] giving 477.
Since matlab convert automatically lists into cells, I have tried changing every values for integers and then using engine.cell2mat directly onto the list, but I get this error:
TypeError: array of MATLAB int64 type cannot be returned on this platform
As of now, I'm still trying to convert a python into one of the MATLAB data formats mentioned above. I run Python 2.7.