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); |
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 |
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'); |
currRadioButton = get(get(handles.uibuttongroupView, 'SelectedObject'), 'Tag');
Ähnliche Beiträge