pop up menu regarding
이전 댓글 표시
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
답변 (2개)
Paulo Silva
2011년 9월 5일
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
KSSV
2011년 9월 5일
Paulo Silva
2011년 9월 5일
Please see what you get from
ind = get(handles.popupmenu1,'value') %remove the ; to see the value and
class(ind) %maybe ind is a string instead of a number (double)
Paulo Silva
2011년 9월 5일
I changed one of the example GUIs that comes with MATLAB, the one with the popupmenu and the graphs so it draws the graphs after the user changes the selection (no need to press the pushbutton) and all works just fine, value is always the index number of the selected line, maybe you changed some property of the popupmenu :s
KSSV
2011년 9월 6일
Walter Roberson
2011년 9월 6일
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
2011년 9월 6일
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 ?
카테고리
도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!