Main Content

Callback Button

Execute MATLAB code using button

  • Library:
  • Simulink / Dashboard

  • Callback Button block

Description

The Callback Button block executes MATLAB® code in response to a click or press of the button. When you press the button, the code executes after a time span that you specify has elapsed or at time intervals that you specify. You can configure the block to execute different code for a click versus for a press.

Double-clicking the Callback Button block does not open its dialog box during simulation or when the block is selected. To edit the block parameters, you can use the Property Inspector or open the block dialog box by:

  • Double-clicking the block when the block is not selected and the model is not simulating.

  • Right-clicking the block and selecting Block Parameters from the context menu.

The Callback Button block in the Customizable Blocks library provides the same functionality as this Callback Button block and provides additional capabilities to:

  • Design the appearance of the block to look like a button in a real system.

  • Configure the button type as momentary or latch.

Parameters

expand all

To modify the block parameters of a Callback Button, use the Block Parameters dialog box.

Text label for the button.

Tips

To design a button that displays different text depending on the state of the block, use the Callback Button block in the Customizable Blocks library.

Programmatic Use

Block Parameter: ButtonText
Type: string or character array
Default: 'Callback Button'

MATLAB code that executes in response to a click of the button.

Every time you click the button, the ClickFcn code executes once, at the point in time when you release the click.

To specify code for the ClickFcn, select ClickFcn from the drop-down menu. Enter the code in the text box below the menu.

MATLAB code that executes in response to a press of the button.

While the button is in the pressed state, the PressFcn code executes once when the Press Delay time has elapsed and periodically at every Repeat Interval.

To specify code for the PressFcn, select PressFcn from the drop-down menu. Enter the code in the text box below the menu.

To execute the PressFcn code, hold down your click for the length of time that you want to press the button.

Note

Every time that you click on the button, even when you do so as part of the process for pressing the button, the ClickFcn code executes once, at the point in time when you release the click.

Amount of time required to cause the PressFcn code to execute.

Dependency

Press Delay (ms) is visible only when PressFcn is selected as the Mouse Action.

Time interval after which the PressFcn code executes again if the Callback Button block is still pressed.

Dependency

Repeat Interval (ms) is visible only when PressFcn is selected as the Mouse Action.

Block Characteristics

Data Types

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

Version History

Introduced in R2017b