006 – Radio Button (Matlab Gui)


Matlab GUI – Grafiksel Kullanıcı Arayüzü Dersleri

Ders: 006 – Matlab Gui Radio Button

Matlab GUI tasarım araçlarından Radio Button aracımızı detaylandırdığım video.
Burak Can KARA

Radio Button

This code is an example of a radio button callback function in GUIDE. Associate this function with the radio button Callback property to make it execute when the end user clicks on the radio button.

function radiobutton1_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton1

if (get(hObject,'Value') == get(hObject,'Max'))
	display('Not selected');

The radio button’s Value property matches the Min property when the radio button is not selected. The Value changes to the Max value when the radio button is selected. This callback function gets the radio button’s Value property and then compares it with the Max and Min properties. If the button is selected, then the function displays ‘Selected’ in the Command Window. If the button is not selected, then the function displays ‘Not selected’.

Button Group

Button groups are similar to panels, but they also manage exclusive selection of radio buttons and toggle buttons. When a button group contains multiple radio buttons or toggle buttons, the button group allows the end user to select only one of them.Button Group

Do not code callbacks for the individual buttons that are inside a button group. Instead, use the button group’s SelectionChangedFcncallback to respond when the end user selects a button.

This code is an example of a button group SelectionChangedFcn callback that manages two radio buttons and two toggle buttons.

function uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uibuttongroup1 
% eventdata  structure with the following fields
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'radiobutton1'
        display('Radio button 1');
    case 'radiobutton2'
        display('Radio button 2');
    case 'togglebutton1'
        display('Toggle button 1');
    case 'togglebutton2'
        display('Toggle button 2');

When the end user selects a radio button or toggle button in the button group, this function determines which button the user selected based on the button’s Tag property. Then, it executes the code inside the appropriate case.

Note:   The button group’s SelectedObject property contains a handle to the button that user selected. You can use this property elsewhere in your code to determine which button the user selected.

Kimler Neler Demiş?


This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Abone Ol  
Bildirim Al