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

10 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 9 de En. de 2018
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 comentario
Simon Silge
Simon Silge el 19 de Dic. de 2023
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Subsystems en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by