pyargs() not working in python interface

5 visualizaciones (últimos 30 días)
Matthew Parry
Matthew Parry el 1 de Dic. de 2021
Editada: surya venu el 2 de Abr. de 2024 a las 10:31
When I try to use the inkstone package (https://github.com/alexysong/inkstone) with MATLAB the pyargs() function doesn't work properly.
>>> pip install inkstone
In MATLAB I have
s = py.inkstone.Inkstone();
s.AddMaterial(pyargs('name','di','epsilon',12))
which gives the error
Unrecognized method, property, or field 'AddMaterial' for class 'py.inkstone.simulator.Inkstone'.
I can get around this one by using
s.AddMaterial('di', pyargs('epsilon',12))
But then I get an error with
s.AddLayer('in', pyargs('thickness',0, 'material_background','vacuum'))
Unrecognized method, property, or field 'AddLayer' for class 'py.inkstone.simulator.Inkstone'.
From this point on pyargs() simply won't work and I have to list every argument in the order in which they are defined in the method. This ofcourse makes it impossible to use a method where I don't want to specify a particular argument.
If I use pyargs() at the command line I get
pyargs('y',0)
ans =
pyargs with no properties.

Respuestas (1)

surya venu
surya venu el 2 de Abr. de 2024 a las 10:30
Editada: surya venu el 2 de Abr. de 2024 a las 10:31
Hi,
Listed below are some troubleshooting steps:
  1. Check MATLAB Version and Python Integration: Ensure you're using MATLAB R2016b or later, as earlier versions had limitations with "pyargs()".
  2. Try both "name=value" syntax and "pyargs()" for different methods to see which approach works for each.
  3. For methods like "AddLayer", provide required positional arguments before optional keyword arguments.
  4. From the official documentation of "pyargs" function from MathWorks, there are some limitations mentioned and here is the documention link: https://www.mathworks.com/help/matlab/ref/pyargs.html
  • Do not combine pyargs and name=value syntax when passing keyword arguments to Python functions.
  • MATLAB does not support name,value syntax for passing keyword arguments to Python functions. Use name=value syntax instead.
I hope these steps help you.

Categorías

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

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by