Filter löschen
Filter löschen

How to call python in Matlab?

1 Ansicht (letzte 30 Tage)
Sheng Liu
Sheng Liu am 11 Dez. 2017
Beantwortet: Khushboo am 27 Okt. 2022
This is supposed to be simple because seems no one has this problem. I was told to run this code
py.numpy.zeros([3,3])
in Matlab. But it returns error: Undefined variable "py" or class "py.numpy.zeros".
I installed Python 3.5.3 it doesn't work. Then I tried Python 2.7, also doesn't work. Is there anything special I need to do. BTW, I am using Matlab 2017.
Thank you.

Antworten (1)

Khushboo
Khushboo am 27 Okt. 2022
Hello,
I hope you have done the necessary setup for using Python in MATLAB and imported numpy in your MATLAB code using the following:
py.importlib.import_module('numpy')
More details regarding import can be found here.
Otherwise, it might be an issue with the setup. It would be better to install Python (Cpython) and make sure that numpy library is installed. Then you can launch MATLAB and make sure that MATLAB has loaded Python using the following:
pyversion
If this does not work, it would be really helpful if you could give more details regarding your environment (if you are using Anaconda) and path setup.

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by