Can I call my own custom Matlab functions from python (R2014b)?

15 visualizaciones (últimos 30 días)
Claire
Claire el 10 de Dic. de 2014
Comentada: Tom Sloan el 10 de Ag. de 2020
I've just installed R2014b and am hoping to use the new MATLAB Engine for Python capabilities.
I can successfully call standard functions like isprime from python as shown in the documentation.
Is it possible for me to call my own custom Matlab functions from python using the Engine?

Respuesta aceptada

Bo Li
Bo Li el 10 de Dic. de 2014
Yes, you can also call your own custom MATLAB function from Python Engine. However, you need to add the folder of your own MATLAB file (for example c:\demo\foo.m) into MATLAB path:
>>>eng.addpath(r'c:\demo',nargout=0)
>>>eng.foo()
or change to the directory where your MATLAB file is located:
>>>eng.cd(r'c:\demo')
>>>eng.foo()
If you already have the folder of your MATLAB file in the search path, you can call it directly from Python:
>>>eng.foo()
  3 comentarios
Joshua Bone
Joshua Bone el 17 de Jun. de 2020
What is the purpouse of the "nargout" argument here?
Tom Sloan
Tom Sloan el 10 de Ag. de 2020
@Joshua Bone Its so the engine will know how many variables to expect on the return of the function. You'll find several functions require this (such as the save func). I am not sure why all don't require this. Here's a link to the nargout docs

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Call MATLAB from Python 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