nav-left cat-right
cat-right
Matthias Pospiech > Programming > matlab > radiobuttons in a buttongroup

radiobuttons in a buttongroup

In matlab one has to place radiobuttons in a uibuttongroup to make them exclusively selectable. In the startup of the gui one can select the default selection and define a callback function
set(handles.uibuttongroupView, 'SelectedObject', handles.radiobuttonPlotROI);
set(handles.uibuttongroupView, 'SelectionChangeFcn',@uibuttongroupView_SelectionChangeFcn);
The callback function then looks like
function uibuttongroupView_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uibuttongroupView 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
 
handles=guidata(hObject);
if (~strcmp(get(eventdata.NewValue,'Tag'), get(eventdata.OldValue,'Tag')))
    switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
        case 'radiobuttonPlotROI'
 
        case 'radiobuttonPlotCalibration'
 
        otherwise
            % Code for when there is no match.
    end
end
The current selection can in any gui function be retrieved using he following code, which will get the current tag as a string.
currRadioButton = get(get(handles.uibuttongroupView, 'SelectedObject'), 'Tag');

Einen Kommentar schreiben

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *


*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

WP-SpamFree by Pole Position Marketing