How to set parameters in the MATLAB Function block in Simulink?

123 views (last 30 days)
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?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 Jan 2020
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.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!