How do I stop parameter callback running when opening mask?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a simulink mask with two popups, one affects the other. There is a callback on the first popup to change the values in the second when it changes. My issue is that this callback seems to run when i open the mask, not only when the value is changed, is there any way of preventing this or stopping part of the callback running unless the value has changed.
0 commentaires
Réponses (1)
Tejas
le 28 Fév 2024
Hello Lucinda,
The callback code for “popup” parameters in Simulink is triggered each time a selection is made from the list of options in the “popup”. If you would like to limit changes to the value of a second “popup” until there has been a change in the value of the first “popup”, the “UserData” property of Simulink blocks can be quite handy.
Simulink blocks come with a general-purpose “UserData” property that allows you to store any additional information related to the block. This feature can be used to retain the previous value of the first “popup”. Then, by implementing an if condition, you can ensure that the value of the second “popup” is updated only if there is any difference between the current and the previous values of the first “popup”.
Here is an example of callback code associated with the first “popup”. In this example, when a numerical value is selected from the dropdown list of the first “popup”, the code checks for a change in value. If there is a change, the value of the second “popup” is set to be four times that of the first “popup” value.
pop1='Popup1';
pop2='Popup2';
current = get_param(gcb , pop1);
prev = get_param(gcb, 'UserData');
if ~isempty(prev) && ~strcmp(current, prev)
val = num2str(str2double(current) .* 4) ;
set_param( gcb , pop2 , val);
end
set_param(gcb, 'UserData' , current);
For more information about the “UserData” property, refer this documentation:
Hope it helps!
0 commentaires
Voir également
Catégories
En savoir plus sur Author Block Masks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!