Borrar filtros
Borrar filtros

How to call python in Matlab?

1 visualización (últimos 30 días)
Sheng Liu
Sheng Liu el 11 de Dic. de 2017
Respondida: Khushboo el 27 de Oct. de 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.

Respuestas (1)

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

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by