Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

button group, radio button using guide

1,446 views
Skip to first unread message

viji sai

unread,
Apr 12, 2010, 4:06:03 PM4/12/10
to
i have created a button group with four radio buttons and a push button using guide.

four functions for each radio button written separately.

1.how to call these functions to respective radio buttons.
2.when the push button is pressed, corresponding radio button's function which has been checked should execute.
kindly help me to write a program for this.

thanks

vs

Walter Roberson

unread,
Apr 12, 2010, 5:08:20 PM4/12/10
to

The individual buttons for a uibuttongroup are hidden children of the uipanel
whose handle is returned when the uibuttongroup is created. Hidden in the
sense that their HandleVisibility property is off. allchild() of the handle
returned by the uibuttongroup . The order in the children will be returned in
is the opposite of the order they were added to the group.

Do _not_, however, directly change the Callback property of an individual
button, as uibottongroup will have set the Callback to a function that manages
the group as a whole, deselecting any current selection and selecting the
current one.

Instead, what you should do is set up a SelectionChangeFcn for the
uibuttongroup . Inside the SelectionChangeFcn callback, the evt parameter will
have a field named OldValue which will be the handle of what was previously
selected, and a field named NewValue which will be the handle of what was just
selected.

For a specific programming example, see

http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f10-998412.html#brrll58-1

viji sai

unread,
Apr 14, 2010, 2:09:05 PM4/14/10
to
Thank you. i have solved it. the link was very useful.

Walter Roberson <robe...@hushmail.com> wrote in message <hq0247$est$1...@canopus.cc.umanitoba.ca>...

viji sai

unread,
Apr 19, 2010, 10:16:06 AM4/19/10
to
thank you very much.
with your help, i am now able to call the function for each radio button. however, i get a error message

Reference to non-existent field 'ics_si'

ics_si is my function, which has the following code, i do not know where i am making a mistake

i have created the edit box for user to input the values for bore and stroke. and vdisp is calculated and the result is displayed in the third edit box.

function ics_si_Callback(hObject, eventdata, handles)

b = str2double(get(handles.bore,'String'));
s = str2double(get(handles.stroke,'String'));
vdisp = (pi * b * b * s*10^(-3))/4;
set(handles.vdisp,'String',vdisp);


this code must be called when i press the first or second radio button. i.e. when the radio button is pressed, it should call the function ics_si, calculate it and display the result.
how to get this.


Walter Roberson <robe...@hushmail.com> wrote in message <hq0247$est$1...@canopus.cc.umanitoba.ca>...

Jeff Eriksen

unread,
Dec 1, 2010, 5:10:08 PM12/1/10
to
"viji sai" <viji...@yahoo.com> wrote in message <hpvufa$odn$1...@fred.mathworks.com>...

Hello Viji,

I would like to create a radio button group, and found, on my own, the information in the responses to your questions. But I still do not know how to create, using guide, a radio button group. Could you please enlighten me, or tell me where to find it in the documentation?

Thanks,
-Jeff

John

unread,
Dec 1, 2010, 5:48:06 PM12/1/10
to
Are you sure that you defined the &#8222;SelectionChangeFcn&#8221; at the &#8220;OpeningFcn&#8220; of your Gui? If yes, then whenever you select a radio button in the button group, first your &#8220;SelectionChangeFcn&#8221; will be called. That means, you should write your &#8220;setting edit box string&#8221; script in the &#8220;SelectionChangeFcn&#8221; of the button group. For example:

function yourSelectionChangeFcn(hObject, eventdata)

handles = guidata(hObject);

switch get(eventdata.NewValue, 'Tag')
case 'tagOfFirstRadioButton'


b = str2double(get(handles.bore,'String'));
s = str2double(get(handles.stroke,'String'));
vdisp = (pi * b * b * s*10^(-3))/4;
set(handles.vdisp,'String',vdisp);

case 'tagOfSecondRadioButton'


b = str2double(get(handles.bore,'String'));
s = str2double(get(handles.stroke,'String'));
vdisp = (pi * b * b * s*10^(-3))/4;
set(handles.vdisp,'String',vdisp);

case 'tagOfSecondRadioButton'
% Do something else.

end


Jeff, there is a simple example at the following address:

http://blinkdagger.com/matlab/matlab-gui-tutorial-buttons-button-group/

Regards.

Jeff Eriksen

unread,
Dec 1, 2010, 7:15:07 PM12/1/10
to
"John " <onsekiz...@yahoo.co.uk> wrote in message <id6jb6$788> s = >
> Jeff, there is a simple example at the following address:
>
> http://blinkdagger.com/matlab/matlab-gui-tutorial-buttons-button-group/

John,

Thanks for the detail. All I really needed was to learn that there is a tool to create the "button group" on the guide layout screen. I searched the Matlab documentation for "button group" and never came upon this simple fact. If I would have gone back to the basic guide instructions and read through it I would have happened upon it.

I do not like all these icons, I can never remember what the little pictures mean. I am sure I can figure out the details given your example.

-Jeff

John

unread,
Dec 2, 2010, 4:26:04 AM12/2/10
to
"Jeff Eriksen" <erik...@ohsu.edu> wrote in message <id6oeb$4kb$1...@fred.mathworks.com>...

There is documentation about creating Gui's in Matlab Help.

http://www.mathworks.com/help/techdoc/creating_guis/bqz6p81.html

But if you want to create a special object, you need to use Google for searching. You can also have a look following video, which shows how to create a simple Gui using Guide.

http://www.mathworks.com/videos/matlab/creating-a-gui-with-guide.html

"Little pictures" are your objects in your Gui and each of them has special properties. So you get used to them after creating a few Gui's. No worries!

Regards.

David Dapuero

unread,
Mar 27, 2012, 10:34:13 AM3/27/12
to
Walter Roberson <robe...@hushmail.com> wrote in message <hq0247$est$1...@canopus.cc.umanitoba.ca>...
In these web reference talks about this easy to understand explanation:

function uibuttongroup1_SelectionChangeFcn(hObject,eventdata)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
case 'radiobutton1'
% Code for when radiobutton1 is selected.
case 'radiobutton2'
% Code for when radiobutton2 is selected.
case 'togglebutton1'
% Code for when togglebutton1 is selected.
case 'togglebutton2'
% Code for when togglebutton2 is selected.
% Continue with more cases as necessary.
otherwise
% Code for when there is no match.
end

...but when I try to do so i get the warning: "??? Attempt to reference field of non-structure array."

So..., to get the Tag of the selected one I do this way:

function uipanel17_SelectionChangeFcn(hObject, eventdata, handles)
Tag = get(hObject, 'Tag')
NewValue = get(eventdata.NewValue,'Tag')

The line "Tag = get(hObject, 'Tag') " works and give me the correct tag when I change selection.
But the line "NewValue = get(eventdata.NewValue,'Tag')" doesn´t work and send the message also "??? Attempt to reference field of non-structure array."

Could it be becouse of the use of the "eventdata" extructure and my 7.5 matlab versión?
Or is the problen in other place?

Thanks for your help and colaboration.
David Dapuero

David Dapuero

unread,
Mar 27, 2012, 10:35:11 AM3/27/12
to
Walter Roberson <robe...@hushmail.com> wrote in message <hq0247$est$1...@canopus.cc.umanitoba.ca>...

Steven_Lord

unread,
Mar 27, 2012, 12:08:31 PM3/27/12
to


"David Dapuero" <dap...@gmail.com> wrote in message
news:jksj55$9jv$1...@newscl01ah.mathworks.com...
> Walter Roberson <robe...@hushmail.com> wrote in message
> <hq0247$est$1...@canopus.cc.umanitoba.ca>...
>> viji sai wrote:

*snip*

> In these web reference talks about this easy to understand explanation:
>
> function uibuttongroup1_SelectionChangeFcn(hObject,eventdata)
> switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
> case 'radiobutton1'
> % Code for when radiobutton1 is selected.
> case 'radiobutton2'
> % Code for when radiobutton2 is selected.
> case 'togglebutton1'
> % Code for when togglebutton1 is selected.
> case 'togglebutton2'
> % Code for when togglebutton2 is selected.
> % Continue with more cases as necessary.
> otherwise
> % Code for when there is no match.
> end
>
> ...but when I try to do so i get the warning: "??? Attempt to reference
> field of non-structure array."

How did you add the buttongroup's SelectionChangeFcn to your GUI? While this
property can accept either a string or a function handle, I would strongly,
STRONGLY recommend you specify it as a function handle.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

David Dapuero

unread,
Mar 27, 2012, 3:00:18 PM3/27/12
to

> How did you add the buttongroup's SelectionChangeFcn to your GUI? While this
> property can accept either a string or a function handle, I would strongly,
> STRONGLY recommend you specify it as a function handle.

Hallo!

I added the SlectionChangeFcn just by rigth clicking on the buttongroup area and callbacks...

Didn´t know about different ways of adding a function...
I have just got a GUI quite big communicating variables with other GUI, but probably I still don´t understand some things. Can you be more explicit in your answer or linking some reference about that?

Thank you very much Steven Lord,
David Dapuero
0 new messages