Setparam on a nested block
Mostrar comentarios más antiguos
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 comentario
Tommaso Proietti
el 18 de Ag. de 2020
Respuestas (1)
Fangjun Jiang
el 15 de Ag. de 2020
0 votos
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 comentarios
Tommaso Proietti
el 15 de Ag. de 2020
Editada: Tommaso Proietti
el 15 de Ag. de 2020
Fangjun Jiang
el 17 de Ag. de 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
el 17 de Ag. de 2020
Categorías
Más información sobre System Configuration en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!