How to set parameters in the MATLAB Function block in Simulink?
조회 수: 69 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 1월 17일
답변: MathWorks Support Team
2020년 3월 30일
I have a blank Simulink model, and I want to place a MATLAB Function block and be able to edit the parameters in it via Simulink.
How do I do it?
채택된 답변
MathWorks Support Team
2020년 1월 17일
In the Simulink model put a MATLAB Function block.
Double click on it to open the function in MATLAB Editor, and add additional parameters, e.g. "param1" to the function signature. Then in Editor tab under Simulink subtab click on "Edit Data" in order to open the Ports and Data Manager. Click on the new parameter, and in the General tab change the scope to be "Parameter", and click on "Apply" to save this
Then back in Simulink right click Mask > Create Mask, open "Parameters & Dialog" tab. On the left pane it shows "Controls", choose "Edit" control and drag it to "Dialog box" in the middle pane.
Change the name of this control to be the name of the parameter, e.g. "param1". Then set the default value and prompt, e.g. 1 and "Parameter 1". Click on "OK" at the bottom of the window to save this mask.
Now if you double click on the Function block, it will allow to change the default value for the parameter used in the block. You can go back to the source code of the block by clicking the arrow at the bottom left corner, should you wish to make further changes to the function itself.
For more information on adding parameter arguments, please see the documentation page in https://www.mathworks.com/help/simulink/ug/parameter-arguments-in-matlab-function-block-functions.html.
An example "function_block_parameters.slx" has been attached to this answer and the screenshot of the model is shown below.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!