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

5 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 9 Mar 2023
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:

Plus de réponses (0)

Catégories

En savoir plus sur Author Block Masks dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by