Inconsistent behavior when using "set_param" to set mask parameter values
14 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2023-3-9
回答: MathWorks Support Team
2023-3-9
When I use "set_param" to modify the value of a mask parameter, I found that the success of the modification depends upon:
- whether the mask dialog is open or closed before calling "set_param".
- whether the mask dialog is open or closed after calling "set_param" and before saving a model.
- whether the mask parameter is visible or invisible.
In R2022a, the "set_param" call will modify the model only if the mask dialog is not open. If the mask dialog is open, it may intercept the "set_param" call depending on whether or not the parameter is visible.
I also found that the exact behavior has changed from release to release (changed from R2019b to R2020a and then reverted back from R2021b to R2022a). How can I avoid this inconsistent behavior?
采纳的回答
MathWorks Support Team
2023-3-9
To set mask parameter values, please use "Simulink.Mask" and "Simulink.MaskParameter" classes instead of the "set_param" function. Utilizing these classes to change mask parameters will set/change the parameters, independent of the MATLAB version, whether the parameters are hidden/visible, the mask dialog is open or not.
The following demonstrative piece of code sets the value of a parameter "anyPar" for a masked subsystem "SubSys'" in the model "TestModel":
%Get Subsystem Mask
p = Simulink.Mask.get('TestModel/SubSys');
%Get Parameter from Mask
q = p.getParameter(anyPar);
%Set Parameter Value
q.set('Value','NewValue');
This method is based on the following documentation pages:
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Author Block Masks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!