Main Content

edge

Trigger event

Parent Section: events

Syntax

edge(b)

Description

edge(b) takes a scalar boolean expression b as input. It returns true, and triggers an event, when and only when the input argument changes value from false to true. The return data type of edge is event. Event data type is a special category of boolean type, which returns true only instantaneously, and returns false otherwise.

The following graphic illustrates the difference between boolean and event data types.

edge(b) returns true only when b changes from false to true.

You use the edge operator to define event predicates in when clauses. For more information, see events.

Examples

expand all

To trigger an event on the rising edge of condition b, use:

edge(b)

It returns true when b changes from false to true.

To trigger an event on the falling edge of condition b, use:

edge(~b)

It returns true when b changes from true to false.

To trigger an event both on the rising edge and on the falling edge of condition b, use:

edge(b)||edge(~b)

For more information on data derivation rules between boolean and event data types, see Event Data Type and edge Operator.

To trigger an event at a specific time, for example, 2 seconds after the start of simulation, use:

edge(time>{2.0,'s'})

Related Examples

Version History

Introduced in R2016a