How do I get the value in a Popup in a mask dialog into my subsystem in MATLAB R2016a?

10 ビュー (過去 30 日間)
I have a masked subsystem block with a Popup in the dialog. The Popup options are numbers like 10, 30, 40, etc. I tried to use the variable name associated with the Popup in my subsystem, but instead of having the value from the Popup options it just has the index of the option (If I choose the second option, 30, I get the value 2). How can I get the actual value on the Popup instead?

採用された回答

MathWorks Support Team
MathWorks Support Team 2018 年 1 月 9 日
Because Popup options can be any combination of numerical and string values, by default, Simulink will return an index value to the chosen Popup entry.
Option 1:
Uncheck the "Evaluate" checkbox in the Popup Attributes. There is no evaluation of the string, so you will need to evaluate the string when you access the variable. For example, if 'popupIndex' is your Popup variable, you would need to evaluate "str2double(popupIndex)" to obtain the actual value.
An example of using this approach is shown in option1.slx attached.
Option 2:
You can get the value from the Popup into your subsystem by adding code to the Initialization tab in the Mask Editor. If your Popup variable is "popupIndex" and your Popup options are 10, 30, and 40 you could add the following code to make the variable "popupValue" in your Subsystem to match the Popup option.
switch popupIndex
case 1
popupvalue = 10;
case 2
popupValue = 30;
case 3
popupValue = 40;
end
If you did not have to perform any other actions other than setting the values, the following code would work as well.
options = [10, 30, 40];
popupValue = options[popupIndex];
An example of using this approach is shown in option2.slx attached.
  1 件のコメント
Simon Silge
Simon Silge 2023 年 12 月 19 日
Alternatively, you can use the "combo box" and activate the "evaluate" option. That allows you to provide a list of numbers for the drop-down menu and use them directly without any need for extra code or variables.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubsystems についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by