pop up menu regarding
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi I have a problem in MATLAB pop up menu in GUI...The code looks as follows :
function popupmenu1_Callback(hObject, eventdata, handles,varargin)
% Set current data to the selected data set.
set(handles.popupmenu1,'value',1) ;
ind = get(handles.popupmenu1,'value') ;
switch ind
case 1 % User selects displacement field
set(handles.popupmenu1,'string','displacement')
case 2 % User selects stress field
set(handles.popupmenu1,'string','stress')
end
When I run the above, the pop menu always selects only case 1...it never selects case 2. If I don't set the handles value to 1, when I select case 2 , the following errors comes on the screen and popup menu disappears....
Warning: popupmenu control requires that Value be an integer within String range
Control will not be rendered until all of its parameter values are valid
I tried a lot..but of no use then waste of time...browsed in other tags of math works but they were not helpful....
What is the solution for this??
Thanks in advance
Sreenu
0 Kommentare
Antworten (2)
Paulo Silva
am 5 Sep. 2011
remove this:
% Set current data to the selected data set.
set(handles.popupmenu1,'value',1) ;
and it should work just fine, that code was setting the value to 1 everytime the user changed the popupmenu value
5 Kommentare
Walter Roberson
am 6 Sep. 2011
You are changing the very menu whose callback you are executing! What do you *expect* to have happen??
If you are trying to store the selected entry, then you have to store it in some *other* place. The 'string' property *is* the list of values to select from for a popup menu. You could, for example, set the 'UserData' property, or you could set the 'string' property for something _else_
Walter Roberson
am 6 Sep. 2011
When you execute
set(handles.popupmenu1,'string','stress')
you change the popupmenu to have only a single string in its list -- but your Value (the index in to the list of strings) is still set to 2, which is more than the number of strings you have.
I do not know why you are trying to change the entire contents of the popup menu when the user selects an entry in it ?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Graphics Performance 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!