0

我在 GUI 中有 2 个单选按钮(Radio_1 和 Radio_2)和一个弹出菜单

我想:

1-当用户选择 Radio_1 时,popupmenu 填充了 106、111

2-当用户选择 Radio_2 时,popupmenu 填充了 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

但它不起作用。

4

2 回答 2

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));
于 2013-07-09T13:55:25.417 回答
0

您需要在Callback 函数'String'中设置of (在选中或取消选中时调用)。popupmenuradiobutton radiobutton

这是一个不使用GUIDE的自洽代码:

function test

radio1 = uicontrol(...
    'Style','radiobutton', 'String', '1',...
    'Units','Normalized', 'Position', [0.4 0.5 0.2 0.1],...
    'Callback', @radioCall);

pop = uicontrol(...
    'Style','popupmenu', 'String', '0',...
    'Units','Normalized', 'Position', [0.4 0.3 0.2 0.1]);

    function radioCall(ev, sc)
        if get(radio1, 'Value')
            set (pop, 'String', {'1', '2', '3', '4'});
        else
            set (pop, 'String', {'0'});
        end
    end
end
于 2013-07-08T00:59:36.537 回答