006 – Radio Button (Matlab Gui)

5
812

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
burakcankara@gmail.com

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('Selected');
else
	display('Not selected');
end

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');
end

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.

Advertisement
Önceki İçerik005 – Toggle Button (Matlab Gui)
Sonraki İçerik007 – Chech Box (Matlab Gui)
Abone Ol
Bildirim Al
guest

Bu site, istenmeyenleri azaltmak için Akismet kullanıyor. Yorum verilerinizin nasıl işlendiği hakkında daha fazla bilgi edinin.

5 Yorum
En Yeniler
Eskiler Beğenilenler
Satıriçi Geribildirimi
Tüm yorumları göster.
Gülfem
Gülfem
18 Mayıs 2020 18:26

Merhaba Burak hocam öncelikle cevap verdiğiniz için teşekkür ederim. Bir button group oluşturdum. Groupun içinden bir buton seçildiğinde, çok sayıda parametrelerin olduğu panelden her bir butonun kendisi için gerekli olmayan parametreleri invisible yapmak istedim. İnvisible olduktan sonra başka bir buton seçmek istendiğinde invisible olan parametreler tekrar visible olsun istiyorum. Örnek olarak; buton grouptaki butonlar konut, araç gibi bir kaç farklı seçenekten oluşsun. Paneldeki static textler kat, cephe, yaş, sınıf, motor gücü, motor hacmi, oda sayısı vb olsun. Konut seçildiğinde kat, cephe, yaş, oda sayısı parametreleri visible diğerleri invisible olsun. Tekrar araç butonunda araç seçildiği zaman bu durumda invisible olan parametreler… Devamını oku »

Gülfem
Gülfem
Cevap verilen:   Burak Can KARA
19 Mayıs 2020 01:38

Çokk teşekkür ederim hocam, tamamdır gerçekten mantık basitmiş ve çözüldü. Bir guiden başka bir gui’ye verilerimi nasıl taşırım? 🙂

Gülfem
Gülfem
Cevap verilen:   Burak Can KARA
20 Mayıs 2020 09:58

Teşekkür ederim, hemen inceliyorum 🙂