Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
GUI - grouping radio buttons

Subject: GUI - grouping radio buttons

From: Mark

Date: 27 Nov, 2008 20:16:02

Message: 1 of 3

I'm trying to make a button group with 2 radio buttons inside it. I want them to toggle between each other and never have both on or off at the same time. With that, I want to store the value generated into a variable to use in an if then statement later in my code.

Also, I want to set one of the buttons as default on when the gui starts.

How do I do all of this?

Sincerely,
Mark

Subject: GUI - grouping radio buttons

From: Mark

Date: 27 Nov, 2008 20:56:02

Message: 2 of 3

I also want to note that I'm using GUIDE to set the position and names of the group and radio buttons along with everything else in my GUI. I then go into the code and tie it into what I need the GUI to do.

I read through many other threads on similar issues, but didn't find any that used GUIDE in making the set-up I'm trying for. I found some code and tweaked it a bit, but it still doesn't work. Here's what I found and edited to suit my needs:

heartrate=uibuttongroup('Position',[.85 .85 .13 .03], 'SelectionChangeFcn',@grv,'units','normalized');
    uicontrol('Style','Radiobutton','Parent',heartrate,'String','Rest (60 bpm)', 'Position',[0 1 1 1],'units','normalized');
    uicontrol('Style','Radiobutton','String','Exercise (120 bpm)', 'Position',[0 0 1 1],'Parent',heartrate,'units','normalized');

I have no clue what the @grv code means, but when I run this, that gives me errors.

Subject: GUI - grouping radio buttons

From: Dave Brackett

Date: 29 Nov, 2008 16:56:02

Message: 3 of 3

"Mark " <rs_camaro92@remove.thishotmail.com> wrote in message <ggn1h2$jab$1@fred.mathworks.com>...
> I also want to note that I'm using GUIDE to set the position and names of the group and radio buttons along with everything else in my GUI. I then go into the code and tie it into what I need the GUI to do.
>
> I read through many other threads on similar issues, but didn't find any that used GUIDE in making the set-up I'm trying for. I found some code and tweaked it a bit, but it still doesn't work. Here's what I found and edited to suit my needs:
>
> heartrate=uibuttongroup('Position',[.85 .85 .13 .03], 'SelectionChangeFcn',@grv,'units','normalized');
> uicontrol('Style','Radiobutton','Parent',heartrate,'String','Rest (60 bpm)', 'Position',[0 1 1 1],'units','normalized');
> uicontrol('Style','Radiobutton','String','Exercise (120 bpm)', 'Position',[0 0 1 1],'Parent',heartrate,'units','normalized');
>
> I have no clue what the @grv code means, but when I run this, that gives me errors.


You can create a radiobutton panel in guide which will only let you select one radiobutton at a time.

To set the defaults set the value to 1 for selected and 0 for unselected for each radiobutton using set(radiobutton1,'Value',1). Put this in the part of the m file towards the top which is carried out before the GUI is displayed.

Tags for this Thread

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.

Contact us