Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

uiradiobutton

(App Designer) Create radio button component

Use only with App Designer or figures created with the uifigure function. When using GUIDE or the figure function, create a radio button using uicontrol.

Syntax

rb = uiradiobutton
rb = uiradiobutton(parent)
rb = uiradiobutton(___,Name,Value)

Description

rb = uiradiobutton creates a radio button within a button group in a UI figure and returns the RadioButton object.

rb = uiradiobutton(parent) creates the radio button within the specified button group. The button group must be child of a Figure created with the uifigure function.

example

rb = uiradiobutton(___,Name,Value) specifies RadioButton properties using one or more Name,Value pair arguments. Use this option with any of the input argument combinations in the previous syntaxes.

Input Arguments

collapse all

Parent container, specified as a ButtonGroup object. The parent must be a ButtonGroup object within a Figure created using the uifigure function.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Text', 'French' specifies that the text “French” displays next to the radio button.

The properties listed here are a subset of the available properties. For the full list, see RadioButton Properties.

collapse all

State of radio button, specified as 1 (true) or 0 (false). Within a button group, only one button can be selected at a time. The state of the first radio button added to a button group is 1, by default. Subsequent buttons added to the same button group have a default state of 0.

When the Value property of a RadioButton changes to 1, the Value of the property for the previously selected RadioButton changes to 0. In addition, the SelectedObject property value of the parent ButtonGroup is updated.

If you programmatically change the Value property of a RadioButton to 0, MATLAB® sets the Value property of the first RadioButton added to the ButtonGroup to 1. If the first RadioButton added is the one for which you programmatically set the Value property to 0, then MATLAB sets the Value property for the second RadioButton added to the ButtonGroup to 1.

Note

The first RadioButton added to a ButtonGroup is not necessarily the first RadioButton listed in the Children property of the ButtonGroup.

Button label, specified as a character vector or a cell array of character vectors. Specify a character vector to label the button with a single line of text. Use cell array to label the button with multiple lines of text. Each element in the cell array represents a separate line of text.

Location and size of radio button, specified as a vector of the form [left bottom width height]. This table describes each element in the vector.

ElementDescription
leftDistance from the inner left edge of the button group to the outer left edge of the radio button
bottomDistance from the inner bottom edge of the button group to the outer bottom edge of the radio button
widthDistance between the right and left outer edges of the radio button (including text)
heightDistance between the top and bottom outer edges of the radio button

The Position values are relative to the drawable area of the button group. The drawable area is the area inside the borders of the button group and does not include the area occupied by the title.

All measurements are in pixel units.

Examples

collapse all

Create a button group in a window.

fig = uifigure('Position',[680 678 398 271]);
bg = uibuttongroup(fig,'Position',[137 113 123 85]);   

Create three RadioButton objects, and specify the parent and location of each.

rb1 = uiradiobutton(bg,'Position',[10 60 91 15]);
rb2 = uiradiobutton(bg,'Position',[10 38 91 15]);
rb3 = uiradiobutton(bg,'Position',[10 16 91 15]);

Change the text associated with each radio button.

rb1.Text = 'English';
rb2.Text = 'French';
rb3.Text = 'German';

Change the radio button selection to German.

rb3.Value = true;

Determine the font name of the German radio button text.

font = rb3.FontName
font =

Helvetica

Tips

  • Button groups can contain any UI component type, but can only manage the selection of radio buttons and toggle buttons.

  • To make your program respond when the user selects a radio button or toggle button that is inside a button group. define a SelectionChangedFcn callback function for the ButtonGroup. You cannot define callbacks for the individual buttons.

  • To determine which radio button or toggle button is selected, query the SelectedObject property of the ButtonGroup. You can execute this query anywhere in your code.

  • If you set the Visible property of a button group object to 'off', then any child objects it contains become invisible along with the parent ButtonGroup. However, the Visible property value of each child object remains unaffected.

Introduced in R2016a

Was this topic helpful?