필터 지우기
필터 지우기

Python support in Matlab Function Block

조회 수: 1 (최근 30일)
Andrew Barth
Andrew Barth 2019년 5월 22일
댓글: Andrew Barth 2019년 5월 31일
I would like to call a python function from a Matlab Function Block within Simulink. When I try this, I get an "Undefined function or variable 'py.[funcion name]'. This occurs for all python functions, even native ones like 'int'. I can call pyversion from the Matlab Function block and it returns the correct python installation information. These python functions work as exected when I call them from the Matlab Command Window or from a script invoked from the command window, just not in my Matlab Function Block. Is there something special I need to do in order to get Simulink to recognize 'py.*'? I am using Matlab 2018b.
-Thanks for your help.
  댓글 수: 1
Jim Riggs
Jim Riggs 2019년 5월 22일
This question interests me too.

댓글을 달려면 로그인하십시오.

답변 (1개)

Shivam Sardana
Shivam Sardana 2019년 5월 30일
There is a similar question which may be of relevance to you: https://www.mathworks.com/matlabcentral/answers/359575-how-to-run-a-python-code-on-simulink
  댓글 수: 1
Andrew Barth
Andrew Barth 2019년 5월 31일
I have found that I can call most python functions from within the Matlab Function block if I add a coder.extrinsic('py.myfunc'); line for each function I wish to call. However, this still does not work for all functions. I'm not exactly sure why some are different.
I have implemented a workaround where I perform the majority of python function calls in a m-file function and then within the Simulink Matlab Function block I add the line: coder.extrinsic('mfile_function');. This treats the entire function as extrinsic. This works, but I lose the ability to run the debugger on that function and I believe it may make things more difficult when I try to autocode my model and intetegrate it into other existing code. I have not gotten to that step in the process yet.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by