Main Content

after

Execute chart after event broadcast or specified time

Description

example

after(n,E) returns true if the event E has occurred at least n times since the associated state became active. Otherwise, the operator returns false.

example

after(n,tick) returns true if the chart has woken up at least 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

after(n,time_unit) returns true if at least n units of time have elapsed since the associated state became active. Otherwise, the operator returns false.

In charts in a Simulink model, 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.

In standalone charts in MATLAB®, specify n with a value greater than or equal to 0.001 and time_unit as seconds (sec). The operator creates a MATLAB timer object that generates an implicit event to wake up the chart. MATLAB timer objects are limited to 1 millisecond precision. For more information, see Events in Standalone Charts.

  • The timer object is created when the chart finishes executing the entry actions of the associated state and its substates. If you specify n as an expression whose value changes during chart execution, the chart does not adjust the temporal delay of the timer object.

  • The timer object starts running at the end of the chart step when the associated state becomes active. This step can include the execution of other parallel states in the chart.

  • If the chart is processing another operation when it receives the implicit event from the timer object, the chart queues the event. When the current step is completed, the chart processes the event.

  • If the state associated with the temporal logic operator becomes inactive before the chart processes the implicit event, the event does not wake up the chart.

Examples

expand all

Display a status message when the chart processes a broadcast of the event E, starting on the third broadcast of E after the state became active.

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

Stateflow chart that uses the after operator in a state.

Transition out of the associated state when the chart processes a broadcast of the event E, starting on the fifth broadcast of E after the state became active.

after(5,E)

Stateflow chart that uses the after operator in a transition.

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

In charts in a Simulink model, enter:

[after(5,E)]

Stateflow chart that uses the after operator in a transition.

Conditional notation for temporal logic operators is not supported in standalone charts in MATLAB.

Transition out of the associated state when the chart wakes up for at least the seventh time since the state became active, but only if the variable temp is greater than 98.6.

after(7,tick)[temp > 98.6]

Stateflow chart that uses the after operator in a transition.

Set the temp variable to LOW every time that the chart wakes up, starting when the associated state is active for at least 12.3 seconds.

on after(12.3,sec):
   temp = LOW;

Stateflow chart that uses the after operator in a state.

Tips

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

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

  • The timing for absolute-time temporal logic operators depends on the type of Stateflow chart:

    • Charts in a Simulink model define absolute-time temporal logic in terms of simulation time.

    • Standalone charts in MATLAB define absolute-time temporal logic in terms of wall-clock time, which is limited to 1 millisecond precision.

    The difference in timing can affect the behavior of a chart. For example, suppose that this chart is executing the during action of state A.

    Stateflow chart with two states. The during action in state A calls a function f. The transition to state B uses the expression after(2,sec). The entry action in state B displays the elapsed time.

    • In a Simulink model, the function call to f executes in a single time step and does not contribute to the simulation time. The transition from state A to state B occurs the first time the chart wakes up and state A has been active for at least 2 seconds. The value displayed by the entry action in state B depends only on the step size used by the Simulink solver.

    • In a standalone chart, the function call to f can take several seconds of wall-clock time to complete. If the call lasts more than two seconds, the chart queues the implicit event associated with the after operator. The transition from state A to state B occurs when the function f finishes executing. The value displayed by the entry action in state B depends on the time the function call to f takes to complete.

Version History

Introduced in R2014b