How do I stop parameter callback running when opening mask?

조회 수: 8 (최근 30일)
lucinda douglas
lucinda douglas 2021년 8월 18일
답변: Tejas 2024년 2월 28일
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.

답변 (1개)

Tejas
Tejas 2024년 2월 28일
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-purposeUserData 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 UserDataproperty, refer this documentation:
Hope it helps!

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by