Documentation

edge

Trigger event

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

edge(b) returns true when b changes from false to true, that is, triggers an event on the rising edge of condition b.

To trigger an event on the falling edge of condition b, use edge(~b).

To trigger an event both on the rising edge and on the falling edge of condition b, use edge(b)||edge(~b) as the event predicate in the when clause. 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'}).

Introduced in R2016a

Was this topic helpful?