Inconsistent behavior when using "set_param" to set mask parameter values
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 9 Mär. 2023
Beantwortet: MathWorks Support Team
am 9 Mär. 2023
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?
Akzeptierte Antwort
MathWorks Support Team
am 9 Mär. 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:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Author Block Masks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!