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.

uibutton

(App Designer) Create push button or state button component

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

Syntax

btn = uibutton
btn = uibutton(style)
btn = uibutton(parent)
btn = uibutton(parent,style)
btn = uibutton(___,Name,Value)

Description

btn = uibutton creates a push button in a new UI figure window and returns the Button object.

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

example

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

example

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

example

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.

Input Arguments

collapse all

Type 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 object, specified as a Figure created using the uifigure function, or one of its child containers: Tab, Panel, or ButtonGroup.

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.

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.

Examples

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 =

Helvetica

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 UI figure window
fig = uifigure;

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

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

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

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

Introduced in R2016a

Was this topic helpful?