Main Content

removeMember

R2026b

Remove button from selection group

Since R2026b

    Description

    removeMember(sg,b) removes a radio button or toggle button from the specified selection group.

    example

    Examples

    collapse all

    Create a selection group that manages three toggle buttons.

    fig = uifigure(Position=[100 100 200 200]);
    gl = uigridlayout(fig,[3 1]);
    tb1 = uitogglebutton(gl,Text="English");
    tb2 = uitogglebutton(gl,Text="French");
    tb3 = uitogglebutton(gl,Text="German");
    sg = uiselectiongroup([tb1 tb2 tb3]);

    Figure containing three toggle buttons labeled English, French, and German. The first button is selected.

    Then remove the first button from the group. The removeMember function removes the button from the group but does not delete the button. By default, the first button in the modified selection group is selected. The original first button remains selected.

    removeMember(sg,tb1);

    Figure containing three toggle buttons labeled English, French, and German. The first and second buttons are selected.

    Create a grid layout in a figure with seven radio buttons managed by a selection group and a check box.

    fig = uifigure(Position=[100 100 800 100]);
    gl = uigridlayout(fig,[2 7]);
    rb1 = uiradiobutton(gl,Text="Monday");
    rb2 = uiradiobutton(gl,Text="Tuesday");
    rb3 = uiradiobutton(gl,Text="Wednesday");
    rb4 = uiradiobutton(gl,Text="Thursday");
    rb5 = uiradiobutton(gl,Text="Friday");
    rb6 = uiradiobutton(gl,Text="Saturday");
    rb7 = uiradiobutton(gl,Text="Sunday");
    sg = uiselectiongroup([rb1 rb2 rb3 rb4 rb5 rb6 rb7]);
    cb = uicheckbox(gl,Text="Exclude Weekend");
    cb.Layout.Column = [1 2];

    Figure containing seven radio buttons and a checkbox. The radio buttons are labeled with the days of the week, starting with Monday.

    Write a callback function named toggleWeekend that controls whether the Saturday and Sunday buttons are enabled and part of the selection group. This callback executes when a user interacts with the check box. Save the function in a folder that is on the MATLAB path.

    function toggleWeekend(src,event,sg,rb6,rb7)
        if src.Value == 1
            sg.removeMember([rb6 rb7])
            rb6.Enable = "off";
            rb7.Enable = "off";
        elseif src.Value == 0
            sg.addMember([rb6 rb7])
            rb6.Enable = "on";
            rb7.Enable = "on";
        end
    end
    
    cb.ValueChangedFcn = @(src,event) toggleWeekend(src,event,sg,rb6,rb7);

    Figure containing seven radio buttons and a checkbox. The radio buttons are labeled with the days of the week, starting with Monday.

    Input Arguments

    collapse all

    Selection group, specified as a SingleSelectionGroup object created using the uiselectiongroup function.

    Button to remove, specified as an array of RadioButton objects or an array of ToggleButton objects. The specified buttons must be members of the selection group sg.

    Version History

    Introduced in R2026b