python library in simulink matlab system block

1 visualizzazione (ultimi 30 giorni)
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 Commento
David Håkansson
David Håkansson il 24 Ago 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?

Accedi per commentare.

Risposte (0)

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by