Manage the Input Trigger of a MATLAB Function Block - MATLAB & Simulink (original) (raw)

Main Content

An input trigger is an input that executes the MATLAB Function block when activated. See Using Triggered Subsystems. You can add one input trigger to each MATLAB Function block and configure the input trigger by using theSymbols pane and Property Inspector or the Model Explorer.

Create an Input Trigger

To create an input trigger, use theSymbols pane (since R2022a) or the Model Explorer.

To use the Symbols pane:

  1. Double-click the MATLAB Function block to open the MATLAB Function Block Editor.
  2. In the Function tab, click Edit Data.
  3. Click the Create Event button and select .

To delete the input trigger, right-click the input trigger name and select .

To use the Model Explorer:

  1. Open the Model Explorer. In the Modeling tab, in theDesign section, click Model Explorer.
  2. In the pane, select the MATLAB Function block.
  3. Click > or the Add Trigger button .

To delete the input trigger, select the input trigger output and click > or the Delete button .

Enable a MATLAB Function Block with an Input Trigger

This example uses a MATLAB Function block that is controlled by an either input trigger.

When the signal from the Square Wave Generator block rises or falls below 0, the MATLAB Function block executes. Double-click the MATLAB Function block to open the code.

function [y1,y2] = fcn(u)

The MATLAB Function block outputs the last propagated value until the block triggers again. Run the model and open the Scope block to see the outputs.

Set Input Trigger Properties

To adjust the input trigger properties, use the Symbols pane and Property Inspector or the Model Explorer.

To edit the properties by using the Symbols pane and Property Inspector, specify the input trigger and open the Property Inspector by using of one of these approaches:

To edit the properties by using the Model Explorer, click the input trigger.

You can modify the following properties.

Name

Specifies the name of the input trigger. Use the naming conventions used in MATLABĀ®. You can only set this property in the Symbols pane or Model Explorer.

Port

Specifies the index of the port associated with the input trigger. The property is read-only. Because you can only add one trigger to a MATLAB Function block, this property is always 1.

Trigger

Specifies the type of event that triggers the MATLAB Function block. You can select one of the following types:

Trigger Event Description
Rising The trigger signal executes the MATLAB Function block when the signal rises from a negative or zero value to a positive value or from a negative value to zero.
Falling The trigger signal executes the MATLAB Function block when the signal falls from a positive or zero value to a negative value or from a positive value to zero..
Either The trigger signal executes the MATLAB Function block when the control signal is either Rising orFalling.
Function call A trigger signal from a block that outputs function-call events executes theMATLAB Function block.

Description

Specifies the description of the input trigger.

Specifies the link to the documentation for the input trigger. You can enter a URL address or a MATLAB command that displays documentation, such as an HTML file or text in the MATLAB Command Window. When you click the Document link link, the MATLAB Function block evaluates the link and displays the documentation.

See Also

MATLAB Function Block Editor

Topics