How to set parameters in the MATLAB Function block in Simulink?
69 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 17 de En. de 2020
Respondida: MathWorks Support Team
el 30 de Mzo. de 2020
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?
Respuesta aceptada
MathWorks Support Team
el 17 de En. de 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.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Programmatic Model Editing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!