Using Matlab in Python

조회 수: 4 (최근 30일)
Rachael Hardman
Rachael Hardman 2017년 5월 12일
댓글: Seth Wagenman 2020년 9월 15일
Hello,
I'm trying to execute matlab functions in python using the Matlab python package. However, when running an example from the documentation, I am getting an error message. When I run the code:
import matlab
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 "<ipython-input-7-6ccc095b323c>", line 1, in <module>
runfile('/Users/rach/Google Drive/PHD/Programming/Winds/Trying.py', wdir='/Users/rach/Google Drive/PHD/Programming/Winds')
File "//anaconda/envs/netcdf/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "//anaconda/envs/netcdf/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
builtins.execfile(filename, *where)
File "/Users/rach/Google Drive/PHD/Programming/Winds/Trying.py", line 4, 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? Is it something to do with how I have installed everything?
Thanks, Rachael

채택된 답변

Nagarjuna Manchineni
Nagarjuna Manchineni 2017년 5월 15일
Looking at the error message, I can see that you are using the python from the Anaconda distribution. This version of Python is not supported with MATLAB. CPython is the recommended Python distribution for use with MATLAB Engine for Python, as noted at the following links:
I believe once you install the correct version you will not encounter the same issue.
  댓글 수: 3
Juan Salcedo
Juan Salcedo 2019년 12월 18일
Can you elaborate. I am also using the Anaconda thing and want to run Matlab commands
Seth Wagenman
Seth Wagenman 2020년 9월 15일

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by