Update Parameter On a Mask During Execution

5 views (last 30 days)
Hi,
I'm wondering if its possible to update a parameter on a mask during execution from within the model itself. I understand that externally I can set_param('blockPath',Value,XX). This isn't what I want to do, I want the simulink model to update a parameter and have that updated value read by the model. Data Store blocks seem like they work mostly, but they do not work for masks. If for instance I have a parameter P, which is defined in the data dictionary, I can update that parameter P using a data memory write/read how can I get my masked subsystem to fetch that newly updated value?
Limitations appear to be that subsystem mask parameters are only read at model initialization. Is this true?
Thanks,

Accepted Answer

Adarsh
Adarsh on 30 Apr 2025
I see that you are looking for a way to update the mask parameters of a block at the time of execution. To update the mask parameters at time of execution you can use the “Parameter Writer” block in Simulink.
As per the documentation, MATLAB R2021b allows the “Parameter Writer” block to only change the block parameter values in a referenced model by writing to instance parameters belonging to a Model block referencing a model.
To perform the required changes like changing a Masked parameter or workspace variable you can use a later MATLAB version like R2022b or R2024b.
In MATLAB R2024b, “Parameter Writer” block changes block parameter values by writing to one of the following:
  1. A parameter of a block that is tunable during simulation.
  2. An instance parameter that belongs to a Model block that references a model.
  3. A masked subsystem parameter.
  4. A model workspace variable
  5. A base workspace variable
  6. A variable created in “Simulink.data.Dictionary”
Here is a sample Simulink model upon which I have tested the “Parameter Writer” block:
Here the Subsystem contains a “gain” block whose gain value is set to the “Multiplier” masked parameter of the subsystem block as shown below:
Now, the output from the subsystem should be the square of sine wave as we are multiplying the input signal with itself (as gain value is set to sine value).
Here is the output of scope block:
For more information on “Parameter Writer” block you can refer to the following documentation link: https://www.mathworks.com/help/releases/R2024b/simulink/slref/parameterwriter.html
I hope this helps!
  1 Comment
Brent Jarvis
Brent Jarvis on 1 May 2025
That does help. I didn't realize that in 2021b you could only change parameters defined in the model workspace of a reference model. I had tried to use the parameter write block, but as we use data dictionaries and a lot of subsystem references so the parameter writer block didn't find any parameters. Looks like in 2024b there are a lot of kinks worked out with that block. We are updating soon so I can address it then.
Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!