python library in simulink matlab system block

6 次查看(过去 30 天)
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 个评论
David Håkansson
David Håkansson 2021-8-24
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?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by