Main Content

before

Execute chart before event broadcast or specified time

Description

example

before(n,E) returns true if the event E has occurred fewer than n times since the associated state became active. Otherwise, the operator returns false.

example

before(n,tick) returns true if the chart has woken up fewer than n times since the associated state became active. Otherwise, the operator returns false.

The implicit event tick is not supported when a Stateflow® chart in a Simulink® model has input events.

example

before(n,time_unit) returns true if fewer than n units of time have elapsed since the associated state became active. Otherwise, the operator returns false.

Specify time_unit as seconds (sec), milliseconds (msec), or microseconds (usec). If you specify n as an expression, the chart adjusts the temporal delay as the expression changes value during the simulation.

Note

The temporal logic operator before is supported only in Stateflow charts in Simulink models.

Examples

expand all

Display a status message when the chart processes the first and second broadcasts of the event E after the state became active.

on before(3,E):
   disp("ON");

Stateflow chart that uses the before operator in a state.

Transition out of the associated state when the chart processes a broadcast of the event E, but only if the state has been active for fewer than five broadcasts of E.

before(5,E)

Stateflow chart that uses the before operator in a transition.

Transition out of the associated state if the state has been active for fewer than five broadcasts of the event E.

[before(5,E)]

Stateflow chart that uses the before operator in a transition.

Transition out of the associated state when the chart wakes up, but only if the variable temp is greater than 98.6 and the chart has woken up fewer than seven times since the state became active.

before(7,tick)[temp > 98.6]

Stateflow chart that uses the before operator in a transition.

Set the temp variable to MED every time that the chart wakes up, but only if the associated state has been active for fewer 12.3 seconds.

on before(12.3,sec):
   temp = MED;

Stateflow chart that uses the before operator in a state.

Tips

  • You can use quotation marks to enclose the keywords 'tick', 'sec', 'msec', and 'usec'. For example, before(5,'tick') is equivalent to before(5,tick).

  • The Stateflow chart resets the counter used by the before operator each time the associated state reactivates.

Version History

Introduced in R2014b