python library in simulink matlab system block

1 visualización (últimos 30 días)
David Håkansson
David Håkansson el 23 de Ag. de 2021
Editada: David Håkansson el 24 de Ag. de 2021
Hi, I am trying to create a matlab system block in simulink that imports and uses a python library.
After setting up the python environment, I tried the following in the resetImpl method in the matlab system block:
obj.cst = py.importlib.import_module('a valid python library reference')
But that gives me an error:
Function 'py.importlib.import_module' is not supported for code generation. Consider adding coder.extrinsic('py.importlib.import_module') at the top of the function to bypass code generation.'
So I tried to add coder.extrinsic according to the proposal in the error message:
coder.extrinsic('py.importlib.import_module');
obj.cst = py.importlib.import_module('a valid python library reference')
which results in the error:
'Cannot pass a mxArray to 'SystemProp_matlabCodegenValidateAnyProp'.'
Any suggestions?
  1 comentario
David Håkansson
David Håkansson el 24 de Ag. de 2021
In many examples for coder.extrinsic, for example here the parameter needs to be pre-defined before running the extrinsic function. In that example it is on these lines:
y = 0;
y = mymin(N, D);
So that is easy when the data type that the mymin function returns is a double.
In my case I suspect I need to declare obj.cst as a python class before I call py.importlib.import_module. How to do that?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

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

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by