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:
- A parameter of a block that is tunable during simulation.
- An instance parameter that belongs to a Model block that references a model.
- A masked subsystem parameter.
- A model workspace variable
- A base workspace variable
- 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:
I hope this helps!