MATLAB: Accessing data from Radio Buttons

guihandlesradio button

Hello,
perhaps this is a better way to phrase my question. I have a group of radio buttons within a panel. I need to know which one is selected to use in simple "If/Then" statements
If (this radio button is selected && this menu item is clicked) Execute this
I am using the code from an online example
I am trying
get(handles.radiobutton1, 'Value')
to access what it is but no matter which button of the four I have selected all handles are apprearing as zero.
Thank you

Best Answer

I don't know why that would be so. Here is an example. Choosing a radiobutton prints the selected state to the command window.
function [] = radio_panel()
P = uibuttongroup('selectionc',@btngrp_sel,...
'units','pix',...
'pos',[10 10 100 200]);
for ii = 1:4
r(ii) = uicontrol(P,'style','radio',...
'units','pix',...
'pos',[10 10+50*(ii-1) 80 30],...
'string',['radio',num2str(ii)]);
end
guidata(gcf,r) % Save the handle to the radio buttons.
set(P,'selectedO',[]) % Initially no selection.
function [] = btngrp_sel(varargin)
r = guidata(gcbf);
get(r,'value') % Should print a 4 element array. Only one non-zero