Update Parameter On a Mask During Execution

6 次查看(过去 30 天)
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,

采纳的回答

Adarsh
Adarsh 2025-4-30
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 个评论
Brent Jarvis
Brent Jarvis 2025-5-1
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by