Effacer les filtres
Effacer les filtres

How to call python in Matlab?

1 vue (au cours des 30 derniers jours)
Sheng Liu
Sheng Liu le 11 Déc 2017
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.

Réponses (1)

Khushboo
Khushboo le 27 Oct 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.

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by