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 button press. You can specify separate code to execute for a click and a press. When you specify code to execute in response to a press, you can configure the block to execute the code at a specified rate while the button is pressed.

The Callback Button block executes the code for a click when you release the left mouse button with the cursor on the Callback Button. The code for a press executes when you click the Callback Button and hold for the specified Press Delay.

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

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'

Mouse action that causes the MATLAB code to execute.

  • Select ClickFcn to view and edit the code that executes when the Callback Button block is clicked.

  • Select PressFcn to view and edit the code that executes when the button is pressed.

MATLAB code that executes in response to the mouse action.

Dependencies

The MATLAB code displayed depends on the Mouse Action parameter selection.

  • Select ClickFcn to view and edit the code that executes when the Callback Button block is clicked.

  • Select PressFcn to view and edit the code that executes when the button is pressed.

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

Introduced in R2017b