Inconsistent behavior when using "set_param" to set mask parameter values
6 ビュー (過去 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!