2

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

1
  • Your code actually works.... Maybe your python version is not compatible with your Matlab version? Commented Sep 11, 2019 at 13:17

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. I thought that would do the trick but I'm still getting the same error message... does it work for you?
1

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

3 Comments

Thanks. I've added this in now (stupid to forget..) but it's still giving me the same error message. Has it worked for you?
I installed the matlab package and ran your script and it is working with no errors (also without the import matlab line). Perhaps try reinstalling the package?
I restarted spyder, ran the code and it was fine. Then I ran the code again and the error popped up. So I connected to a new kernal and the same thing happened again - it seems to work fine on the first run but then I must connect to a new kernal... weird.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.