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

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)

댓글을 달려면 로그인하십시오.

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2020년 8월 15일

0 개 추천

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

Tommaso Proietti
Tommaso Proietti 2020년 8월 15일
편집: Tommaso Proietti 2020년 8월 15일
Hi Fangjun,
Thanks for the answer. What do you mean by inside a library link? I think all the blocks I tried to access are inside subsystem I built.
For the basic syntax, I was doing the same mistake as you and I spent like 2 hours before understanding it. There are actually two very similar but very different set param commands, one for non-real-time applications (https://www.mathworks.com/help/simulink/slref/set_param.html), one for real-time applications (https://www.mathworks.com/help/xpc/api/setparam.html). The difference is the underscore sign and the number of inputs. So I need the one for real-time applications. ;)
Fangjun Jiang
Fangjun Jiang 2020년 8월 17일
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 2020년 8월 17일
Cool, thanks for your hints!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 System Configuration에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 8월 14일

댓글:

2020년 8월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by