Setparam on a nested block

5 views (last 30 days)
Tommaso Proietti
Tommaso Proietti on 14 Aug 2020
Commented: Tommaso Proietti on 18 Aug 2020
Hello,
I'm trying to use setparam command to modify blocks in a Simulink Real-Time model through a GUI built in App Designer. I was able to change a constant block value in the "first layer" of the Simulink model by using a command like:
setparam(tg,'Constant','Value',1)
At the same time, when trying to set similar constant blocks within subsystem blocks (so lower layers of the Simulink model), I'm getting "invalid parameter" error. The command I'm using is pretty much similar but providing the path to the Constant block. Something like this:
setparam(tg,'Layer1/Layer2/Constant','Value',1)
To be honest, I was able to change parameters at the 2nd level, but not deeper than that.
Is there some sort of limitation in using this setparam command? I couldn't find any reference online but maybe you can help here.
Like, is the problem if the layer name contains spaces (e.g. "Layer 1" instead of "Layer1")? Or maybe it's really limited to one level of nesting?
I'm on Matlab 2020a.
Thanks for any help in advance! :)
  1 Comment
Tommaso Proietti
Tommaso Proietti on 18 Aug 2020
Ok I found the solution. The block I was trying to modify was not containing a value but a variable name and this type of constant block is considered a global parameter in Simulink Real-Time. To access a global parameter, the code is the following:
setparam(tg,'Variable Name',value)

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 15 Aug 2020
There is no limitation regarding how deep can you go to reference the block. The only thing that might prevent you from doing this directly is that the block is inside a library link.
But first, please verify that you've done it correctly in the basic syntax
setparam(tg,'Constant','Value',1) is no good.
It should be something like this
set_param('ModelName/Layer1/ConstantBlockName','Value','1')
  3 Comments
Fangjun Jiang
Fangjun Jiang on 17 Aug 2020
Ok, this is for Simulink Real-Time target. I don't have such a target so I can't try.
Looking at the document, it says "Hierarchical name of the originating block" but none of the examples contains hierarchical names. I believe it is true since you said it worked for blocks in your 2nd layer subsystem. I don't think there is a limitation on the number of layers. The only thing I can think of is that the block parameter has to be specified as "tunable".
It is unlikely that every block and every parameter is accessible in Simulink Real-Time target. Some could be optimized out during code generation. Make sure the block parameters you try to change are specified as "tunable".
If you still have difficulties, contact the Mathworks Tech Support.
Tommaso Proietti
Tommaso Proietti on 17 Aug 2020
Cool, thanks for your hints!

Sign in to comment.

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!