How do I set the popup menu to automatically select the first string when run?

3 visualizaciones (últimos 30 días)
When I run the GUI, this comes up. I have used the following script to set the first string in the popup menu:
function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
set(handles.test_pop,'Value',1);
However, when I run the GUI and click calculate, I get errors because no string in the menu has actually been selected. I tested that the script I added changed the string when I run the GUI by changing the value from 1 to 2 or 3 and it does change the string but it only shows it as the string in the box, it does not seem to select it as the first 'value'. So how do I have it set to 'Choose Material' when it first runs?

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Feb. de 2017
The "Choose Material" entry is the entry that corresponds to Value 1. Popup menus do not have an uncounted "header": every entry counts.
  3 comentarios
Walter Roberson
Walter Roberson el 17 de Feb. de 2017
The only time I have seen that problem is if the callback for selecting the string sets variables that the pop-up initialization neglected to set.
If you have values that must be set by the popup and which are not otherwise set, then move the code for doing the setting into a function. Then in the callback for the popup, just fetch the Value of the popup and call the new function with that value. Then when you want to initialize the popup, call that new function with the value you want as the default.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Environment Customization en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by