在GUI中设置弹出菜单的值

时间:2013-07-07 22:35:19

标签: matlab

我有2个Radiobuttons(Radio_1和Radio_2)以及GUI中的弹出菜单

我想:

1 - 当用户选择Radio_1时,弹出菜单中填充了106,111

AND

2 - 当用户选择Radio_2时,弹出菜单填充240,268

E1=get(handles.Radio_1,'Value');
E2=get(handles.Radio_2,'Value');
if(E1==1)
    set(handels.popupmenu_Food_Sources,'String',{'106','111'});
end

但它不起作用。

2 个答案:

答案 0 :(得分:0)

您需要在'String' 回调函数 中设置popupmenu的{​​{1}}(在{{{ 1}}已选中或未选中)。

以下是不使用 GUIDE

的自洽代码
radiobutton

答案 1 :(得分:0)

我找到了答案:

function test_OpeningFcn(hObject, eventdata, handles, varargin)
str = get(handles.popupmenu1,'String');
set(handles.text1,'String',str(1));
set(handles.uipanel1,'SelectionChangeFcn',@uipanel1_SelectionChangeFcn);
handles.output = hObject;
guidata(hObject, handles);

function popupmenu1_Callback(hObject, eventdata, handles)
        val = get(handles.popupmenu1,'Value');
        str = get(handles.popupmenu1,'String');
        if val ==1
            set(handles.text1,'String',str(1));
        elseif val == 2
            set(handles.text1,'String',str(2));
        elseif val == 3
            set(handles.text1,'String',str(3));
        elseif val == 4
            set(handles.text1,'String',str(4));
        elseif val == 5
            set(handles.text1,'String',str(5));
        end
        guidata(hObject, handles);

function uipanel1_SelectionChangeFcn(hObject, eventdata)
handles=guidata(hObject);
switch get(eventdata.NewValue,'Tag')
    case 'radiobutton1'
    E1str{1}='1';E1str{2}='2';E1str{3}='3';E1str{4}='4';E1str{5}='5';
    set(handles.popupmenu1,'String',E1str);
    case 'radiobutton2'
    E2str{1}='6';E2str{2}='7';E2str{3}='8';E2str{4}='9';E2str{5}='10';
    set(handles.popupmenu1,'String',E2str);
end
str = get(handles.popupmenu1,'String');
set(handles.text1,'String',str(1));