Main Content


Create check box component


cbx = uicheckbox creates a check box in a new figure window and returns the CheckBox object. MATLAB® calls the uifigure function to create the figure.


cbx = uicheckbox(parent) creates the check box in the specified parent container. The parent can be a Figure created using the uifigure function, or one of its child containers.


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


collapse all

Create a check box.

fig = uifigure;
cbx = uicheckbox(fig);

Check box component in a UI figure window. The check box has the text "Check box" to its right.

Create a panel. Then create a check box within the panel.

fig = uifigure;
pnl = uipanel(fig);
cbx = uicheckbox(pnl);

Check box component in a panel in a UI figure window

Create a check box and specify property values.

fig = uifigure;
cbx = uicheckbox(fig, 'Text','Show Value',...
                  'Value', 1,...
                  'Position',[150 50 102 15]);

Check box component in a UI figure window. The check box is selected and has the text "Show Value" to its right.

Clear the check box.

cbx.Value = 0;

Determine the font size of the check box text.

fsize = cbx.FontSize
fsize =


Create a radio button group and a check box. When an app user selects the check box, a radio button is disabled.

Save the following code to disableRadioButton.m on your MATLAB path.

This code creates a window containing a radio button group and a check box. When an app user clears the check box, the check box ValueChangedFcn disables the third radio button.

function disableRadioButton
% Create a figure window:
fig = uifigure('Position',[100 100 229 276]);

% Create a button group and radio buttons:
bg = uibuttongroup('Parent',fig,...
    'Position',[56 77 123 85]);
rb1 = uiradiobutton(bg,'Position',[10 60 91 15]);
rb2 = uiradiobutton(bg,'Position',[10 38 91 15]);
rb3 = uiradiobutton(bg,'Position',[10 16 91 15]);

% Create a check box:
cbx = uicheckbox(fig,'Position',[55 217 102 15],...
    'ValueChangedFcn',@(cbx,event) cBoxChanged(cbx,rb3));

% Create the function for the ValueChangedFcn callback:
function cBoxChanged(cbx,rb3)
val = cbx.Value;
if val
    rb3.Enable = 'off';
    rb3.Enable = 'on';

Run disableRadioButton, and then select the check box. The third radio button is disabled.

Check box component and radio button group in a UI figure window. The check box is selected and the bottom radio button in the button group is disabled.

Input Arguments

collapse all

Parent container, specified as a Figure object created using the uifigure function or one of its child containers: Tab, Panel, ButtonGroup, or GridLayout. If you do not specify a parent container, MATLAB calls the uifigure function to create a new Figure object that serves as the parent container.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Value',1 specifies that the check box is displayed with a check mark.

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

State of the check box, specified as 0 (false) or 1 (true). When the Value property is set to 1, the check box is checked. When the Value property is set to 0, the check box is not checked.

Value changed callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes when the user selects or clears the check box in the app. The callback does not execute if the check box value changes programmatically.

This callback function can access specific information about the user’s interaction with the check box. MATLAB passes this information in a ValueChangedData object as the second argument to your callback function. In App Designer, the argument is called event. You can query the object properties using dot notation. For example, event.PreviousValue returns the previous value of the check box. The ValueChangedData object is not available to callback functions specified as character vectors.

The following table lists the properties of the ValueChangedData object.

ValueValue of check box after most recent app user interaction with it.
PreviousValueValue of check box before most recent app user interaction with it.
SourceComponent that executes the callback.

For more information about writing callbacks, see Callbacks in App Designer.

Location and size of the check box relative to the parent, specified as the vector [left bottom width height]. This table describes each element in the vector.

leftDistance from the inner left edge of the parent container to the outer left edge of the check box
bottomDistance from the inner bottom edge of the parent container to the outer bottom edge of the check box
widthDistance between the right and left outer edges of the check box
heightDistance between the top and bottom outer edges of the check box

The Position values are relative to the drawable area of the parent container. The drawable area is the area inside the borders of the container and does not include the area occupied by decorations such as a menu bar or title.

All measurements are in pixel units.

Example: [200 200 102 15]

Version History

Introduced in R2016a

expand all

See Also