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

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
radio button Mark 27 Nov, 2008 15:20:21
button group Mark 27 Nov, 2008 15:20:20
gui Mark 27 Nov, 2008 15:20:20
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com