How do I set the popup menu to automatically select the first string when run?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
George Gascoyne
am 16 Feb. 2017
Kommentiert: George Gascoyne
am 21 Feb. 2017

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?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 17 Feb. 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 Kommentare
Walter Roberson
am 17 Feb. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Environment Customization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!