How can I enter a mask parameter to a block through an input block in Simulink R2021b?

I have a model in Simulink R2021b, and I am wondering on how to enter a mask parameter to a Simulink block via an input block, instead of entering these values in the Block Properties dialog window.
How can I enter a mask parameter to a block through an input block?

 Accepted Answer

This workflow is supported through the “Parameter Writer” block in Simulink. The “Parameter Writer” block allows writing a value from an input block to a model block parameter or to a model workspace variable.
The following steps guide through this process:
  1. Define names to the parameters in the block of interest, e.g., for the “Signal Generator”, you may wish to define “Amp” and “Freq” for the amplitude and frequency, respectively. Make sure to save these parameters to the Model Workspace, not in MATLAB Workspace.
  2. Go to Model Explorer, open the Model Hierarchy tree, and find the variables names under the Model Workspace root. Make each of these variables an Argument by selecting the checkbox under the “Argument” column. You may wish to revise the values already defined to those variables, and close the Model Explorer.
  3. Encapsulate the block of interest as a referenced model by saving this as a Simulink model. This model will be the referenced model for the upcoming step.
  4. Create a new model, which will serve at the top-level model that contains the referenced model from the previous step. Insert a “Model” block, open it and browse the model you saved in the previous step. Once the referenced model is placed, make sure that you are seeing the top-level model before moving to the next steps.
  5. Insert a “Initialize Function” block, open it, and delete the objects inside except the “Event Listener” block.
  6. Inside the “Initialize Function” block, insert an input block, e.g., a “Constant” block, connect to a “Parameter Writer” block and double click to open. A “Parameter Writer” pop-up window will appear.
  7. Select the parameter to write from the list. Upon selection by clicking in “Apply”, a diamond will appear to indicate parameter linking.
  8. Repeat Step 6 and Step 7 for each parameter you are looking to write this way.
The documentation page for the “Parameter Writer” block in Simulink R2021b is as follows:
A more straightforward workflow can be achieved upon upgrading your version of Simulink to at least R2022b. You can directly link the parameter of interest from the list of available parameters instead of manually creating and setting the parameter upon making the block of interest inside a referenced model. For Simulink R2022b and newer versions, follow from Step 5 through Step 8 from the list of steps above. There is no need to define parameter names in the block of interest. The documentation page for the “Parameter Writer” block in Simulink R2022b is as follows:

More Answers (0)

Categories

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!