Inconsistent behavior when using "set_param" to set mask parameter values

조회 수: 6 (최근 30일)
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
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개)

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by