Thread Subject: Button Group SelectedObject property

Subject: Button Group SelectedObject property

From: Peter Russo

Date: 25 Jun, 2009 14:38:01

Message: 1 of 6

Hi,
I am currently trying to make a gui that contains a button group with three radio buttons in it. I want to write the code so when I click on a push button, it checks which of the radio buttons is selected. Currently I have it read in which one is selected using the get() command with the SelectedObject property. The problem is that this returns a number, not the tags that I entered for the radio buttons. The numbers that get returned are 277.0029, 278.0029, and 279.0029. I could write a switch statement for this to convert the three values into the tags I want, but I'm concerned that these values are arbitrary, and that they might change in the future. Also the code would just look/work a lot better if the get command just returned the tag. The get command that I use is shown below ('radius_grouping' is the tag of the button group)

x=get(handles.radius_grouping,'SelectedObject')

 Does anyone know how to fix this? Thanks

Subject: Button Group SelectedObject property

From: Nathan

Date: 25 Jun, 2009 16:01:46

Message: 2 of 6

On Jun 25, 7:38 am, "Peter Russo" <peter.ru...@gmail.com> wrote:
> Hi,
> I am currently trying to make a gui that contains a button group with three radio buttons in it. I want to write the code so when I click on a push button, it checks which of the radio buttons is selected. Currently I have it read in which one is selected using the get() command with the SelectedObject property. The problem is that this returns a number, not the tags that I entered for the radio buttons. The numbers that get returned are 277.0029, 278.0029, and 279.0029. I could write a switch statement for this to convert the three values into the tags I want, but I'm concerned that these values are arbitrary, and that they might change in the future. Also the code would just look/work a lot better if the get command just returned the tag. The get command that I use is shown below ('radius_grouping' is the tag of the button group)
>
> x=get(handles.radius_grouping,'SelectedObject')
>
>  Does anyone know how to fix this? Thanks

Why not try to see if the values of each button is equal to one? (With
'Value' equal to one, this button is "selected"). However, doing this
you'll need to know what "Tag" they each have (which you should have
edited in GUIDE). Do you mean, perhaps, to retrieve their "String"? If
so, get(handles.radiobutton1,'String')

I'd say go ahead and check which one is "selected" by checking each
value. Three "if" statements would do, unless you can find some other
way to do what you are aiming to do.
Good luck.
-Nathan

Subject: Button Group SelectedObject property

From: Steven Lord

Date: 25 Jun, 2009 16:44:33

Message: 3 of 6


"Peter Russo" <peter.russo@gmail.com> wrote in message
news:h20249$p1u$1@fred.mathworks.com...
> Hi,
> I am currently trying to make a gui that contains a button group with
> three radio buttons in it. I want to write the code so when I click on a
> push button, it checks which of the radio buttons is selected. Currently I
> have it read in which one is selected using the get() command with the
> SelectedObject property. The problem is that this returns a number, not
> the tags that I entered for the radio buttons. The numbers that get
> returned are 277.0029, 278.0029, and 279.0029. I could write a switch
> statement for this to convert the three values into the tags I want, but
> I'm concerned that these values are arbitrary, and that they might change
> in the future.

Your concern is justified. The root object (0) and figure windows with
IntegerHandle set to its default value of 'on' are the main objects whose
handles you can reasonably expect to be "guessable" -- the root is always 0
and figure windows with IntegerHandle 'on' have integer values as their
handles. For other objects in a GUI, the actual value of the handle may be
different each time you open the GUI.

> Also the code would just look/work a lot better if the get command just
> returned the tag. The get command that I use is shown below
> ('radius_grouping' is the tag of the button group)
>
> x=get(handles.radius_grouping,'SelectedObject')
>
> Does anyone know how to fix this? Thanks

x is a handle to a Handle Graphics object, and as such is a valid first
input argument for GET.

    x=get(handles.radius_grouping,'SelectedObject');
    xtag = get(x, 'Tag');

Alternately if you just want the tag and don't need the button's handle, you
can condense this down into one line:

    xtag = get(get(handles.radius_grouping,'SelectedObject'), 'Tag');

--
Steve Lord
slord@mathworks.com

Subject: Button Group SelectedObject property

From: Peter Russo

Date: 25 Jun, 2009 17:40:03

Message: 4 of 6

"Steven Lord" <slord@mathworks.com> wrote in message <h209g8$at3$1@fred.mathworks.com>...
>
> "Peter Russo" <peter.russo@gmail.com> wrote in message
> news:h20249$p1u$1@fred.mathworks.com...
> > Hi,
> > I am currently trying to make a gui that contains a button group with
> > three radio buttons in it. I want to write the code so when I click on a
> > push button, it checks which of the radio buttons is selected. Currently I
> > have it read in which one is selected using the get() command with the
> > SelectedObject property. The problem is that this returns a number, not
> > the tags that I entered for the radio buttons. The numbers that get
> > returned are 277.0029, 278.0029, and 279.0029. I could write a switch
> > statement for this to convert the three values into the tags I want, but
> > I'm concerned that these values are arbitrary, and that they might change
> > in the future.
>
> Your concern is justified. The root object (0) and figure windows with
> IntegerHandle set to its default value of 'on' are the main objects whose
> handles you can reasonably expect to be "guessable" -- the root is always 0
> and figure windows with IntegerHandle 'on' have integer values as their
> handles. For other objects in a GUI, the actual value of the handle may be
> different each time you open the GUI.
>
> > Also the code would just look/work a lot better if the get command just
> > returned the tag. The get command that I use is shown below
> > ('radius_grouping' is the tag of the button group)
> >
> > x=get(handles.radius_grouping,'SelectedObject')
> >
> > Does anyone know how to fix this? Thanks
>
> x is a handle to a Handle Graphics object, and as such is a valid first
> input argument for GET.
>
> x=get(handles.radius_grouping,'SelectedObject');
> xtag = get(x, 'Tag');
>
> Alternately if you just want the tag and don't need the button's handle, you
> can condense this down into one line:
>
> xtag = get(get(handles.radius_grouping,'SelectedObject'), 'Tag');
>
> --
> Steve Lord
> slord@mathworks.com
>

Great, that is exactly what I was looking for! Since x was giving me a number I assumed it was just a number, I didn't realize it was an object itself. Thanks a lot!

Subject: Button Group SelectedObject property

From: yekhiel

Date: 20 Nov, 2009 19:23:19

Message: 5 of 6

Hi,
I am also making a similar gui the only difference is that,I want to write a code so that when I click on a push button,it checks which radio button is selected and based on this computes the value of a variable u. pls can someone help me on the code to write at the callbacks of the push button,group button and radio buttons.Any assistance will be appreciated.

"Peter Russo" <peter.russo@gmail.com> wrote in message <h20249$p1u$1@fred.mathworks.com>...
> Hi,
> I am currently trying to make a gui that contains a button group with three radio buttons in it. I want to write the code so when I click on a push button, it checks which of the radio buttons is selected. Currently I have it read in which one is selected using the get() command with the SelectedObject property. The problem is that this returns a number, not the tags that I entered for the radio buttons. The numbers that get returned are 277.0029, 278.0029, and 279.0029. I could write a switch statement for this to convert the three values into the tags I want, but I'm concerned that these values are arbitrary, and that they might change in the future. Also the code would just look/work a lot better if the get command just returned the tag. The get command that I use is shown below ('radius_grouping' is the tag of the button group)
>
> x=get(handles.radius_grouping,'SelectedObject')
>
> Does anyone know how to fix this? Thanks

Subject: Button Group SelectedObject property

From: Carsten W.

Date: 5 Nov, 2010 14:39:03

Message: 6 of 6

"Steven Lord" <slord@mathworks.com> wrote in message <h209g8$at3$1@fred.mathworks.com>...
>
> "Peter Russo" <peter.russo@gmail.com> wrote in message
> news:h20249$p1u$1@fred.mathworks.com...
> > Hi,
> > I am currently trying to make a gui that contains a button group with
> > three radio buttons in it. I want to write the code so when I click on a
> > push button, it checks which of the radio buttons is selected. Currently I
> > have it read in which one is selected using the get() command with the
> > SelectedObject property. The problem is that this returns a number, not
> > the tags that I entered for the radio buttons. The numbers that get
> > returned are 277.0029, 278.0029, and 279.0029. I could write a switch
> > statement for this to convert the three values into the tags I want, but
> > I'm concerned that these values are arbitrary, and that they might change
> > in the future.
>
> Your concern is justified. The root object (0) and figure windows with
> IntegerHandle set to its default value of 'on' are the main objects whose
> handles you can reasonably expect to be "guessable" -- the root is always 0
> and figure windows with IntegerHandle 'on' have integer values as their
> handles. For other objects in a GUI, the actual value of the handle may be
> different each time you open the GUI.
>
> > Also the code would just look/work a lot better if the get command just
> > returned the tag. The get command that I use is shown below
> > ('radius_grouping' is the tag of the button group)
> >
> > x=get(handles.radius_grouping,'SelectedObject')
> >
> > Does anyone know how to fix this? Thanks
>
> x is a handle to a Handle Graphics object, and as such is a valid first
> input argument for GET.
>
> x=get(handles.radius_grouping,'SelectedObject');
> xtag = get(x, 'Tag');
>
> Alternately if you just want the tag and don't need the button's handle, you
> can condense this down into one line:
>
> xtag = get(get(handles.radius_grouping,'SelectedObject'), 'Tag');
>
> --
> Steve Lord
> slord@mathworks.com
>
Hello,

I am having same trouble with my figure, but haven't been able to solve it with the comments from above so far. My m-file is a figure with several uicontrol elements. When pushing on the button I'd like to check for the radio buttons. Using above suggestions, I always get an error that handles is not a structure.

ecu = uibuttongroup('Tag','ecu','Position',[.025,.88,.4,.1],'Title','SG','SelectionChangeFcn',@RadioECUSelect);
uicontrol('Style','RadioButton','String','MED','Position',[5,5,80,15],'Parent',ecu,'Tag','MED');
uicontrol('Style','RadioButton','String','ME','Position',[85,5,60,15],'Parent',ecu,'Tag','ME');

function PushButton(h,eventdata)
        handles = guidata(h);
        x = get(handles.ecu,'SelectedObject');
        set(testtext,'String',get(x,'Tag'));
end

So far, it seems taht guidata requires a change in the figure. I'd like to have it work also without having changed any radiobutton after initialization.

Any help is highly appreciated.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com