Main Content


Create push button or state button component


btn = uibutton creates a push button in a new figure and returns the Button object. MATLAB® calls the uifigure function to create the figure.

btn = uibutton(style) creates a button of the specified style.


btn = uibutton(parent) creates the button in the specified parent container. The parent can be a Figure created using the uifigure function, or one of its child containers.


btn = uibutton(parent,style) creates a Button of the specified style in the specified parent container.


btn = uibutton(___,Name,Value) creates a Button with properties specified by 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 push button.

fig = uifigure;
btn = uibutton(fig);

Create a state button by specifying the style as 'state'.

fig = uifigure;
btn = uibutton(fig,'state');

fig = uifigure('Name','My Figure');
pnl = uipanel(fig);
btn = uibutton(pnl); 

Create a state button and specify property values.

fig = uifigure;
btn = uibutton(fig,'state',...
               'Text', 'Record',...
               'Value', true,...
               'Position',[50,100, 100, 22]);

Determine the font name of the state button text.

fname = btn.FontName
fname =


Change the font name of the button text.

btn.FontName = 'Arial Narrow';

Create a button and a UI axes. When the app user presses the button, a graph is created.

Create buttonPlot.m on your MATLAB path. This code creates a window containing a button and a UI axes. When the app user clicks the button, the ButtonPushedFcn plots some data.

function buttonPlot
% Create a figure window
fig = uifigure;

% Create a UI axes
ax = uiaxes('Parent',fig,...
            'Position', [104, 123, 300, 201]);   

% Create a push button
btn = uibutton(fig,'push',...
               'Position',[420, 218, 100, 22],...
               'ButtonPushedFcn', @(btn,event) plotButtonPushed(btn,ax));

% Create the function for the ButtonPushedFcn callback
function plotButtonPushed(btn,ax)
        x = linspace(0,2*pi,100);
        y = sin(x);

Run buttonPlot, and then click the push button. MATLAB plots the data.

Input Arguments

collapse all

Style of button, specified as one of the following:

  • 'push'

    When clicked once, the button appears to press and release.

  • 'state'

    When clicked once, the button remains in the pressed or released state until it is clicked again.

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 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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Each type of Button object supports a different set of properties. For a full list of properties and descriptions for each type, see the associated property page.

Introduced in R2016a