|
"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.
|