I'm trying to execute matlab functions in python using the Matlab python package. However, when running a simple example from the Mathworks website, I am getting an error message. When I run the code:
import matlab.engine
eng = matlab.engine.start_matlab()
a = matlab.double([1,4,9,16,25])
b = eng.sqrt(a)
print(b)
I get the error message:
File "/dir/Trying.py", line 27, in <module>
a = matlab.double([1,4,9,16,25])
File "//anaconda/envs/netcdf/lib/python2.7/site-packages/matlab/mlarray.py", line 51, in __init__
raise ex
TypeError: 'NoneType' object is not callable
What does this error mean? I can call functions that don't include lists OK but as soon as I try to pass a vector/list through I get the same error. I need to pass m x n arrays through so this is the key to doing that.
Thanks
-
Your code actually works.... Maybe your python version is not compatible with your Matlab version?Ville– Ville2019年09月11日 13:17:20 +00:00Commented Sep 11, 2019 at 13:17
2 Answers 2
you are calling .double form matlab which is not define, I think you need to import matlab as well, from https://www.mathworks.com/help/compiler_sdk/python/matlab-arrays-as-python-variables.html. P/s: I did not use matlab before
import matlab.engine
import matlab
eng = matlab.engine.start_matlab()
a = matlab.double([1,4,9,16,25])
b = eng.sqrt(a)
print(b)
1 Comment
According to https://nl.mathworks.com/help/matlab/matlab_external/get-started-with-matlab-engine-for-python.html
The function Double is contained in the package matlab and not matlab.engine. Have you tried just importing the package matlab?
import matlab