temporalCount

Number of events, chart executions, or time since state became active

Description

temporalCount(E) increments by 1 and returns a positive integer value for each occurrence of the base event E that takes place after activation of the associated state. Otherwise, the operator returns a value of 0.

In a chart with no input events, temporalCount(tick) returns the number of times that the chart has woken up since activation of the associated state.

The temporalCount operator resets the counter for E to 0 each time the associated state reactivates.

Use of temporalCount as an event-based temporal logic operator is not supported in charts for execution as MATLAB® objects.

example

temporalCount(time_unit) counts and returns the number of units of time that have elapsed since activation of the associated state. Specify time_unit as seconds (sec), milliseconds (msec), or microseconds (usec).

The temporalCount operator resets the counter for sec, msec and usec to 0 each time the associated state reactivates.

Examples

expand all

Store the element of the array M indexed by the number of chart executions since the activation of the state.

du:
   y = M[temporalCount(tick)];

Store the number of seconds between activation and deactivation of the state.

exit:
   y = temporalCount(sec);

Tips

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

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

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

    • Standalone charts in MATLAB define temporal logic in terms of wall-clock time.

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

    • In a Simulink model, the function call to f executes in a single time step and does not contribute to the simulation time. After calling the function f, the chart assigns a value of zero to y.

    • In a standalone chart, the function call to f can take several seconds of wall-clock time to complete. After calling the function f, the chart assigns the nonzero time that has elapsed since state A became active to y.

Introduced in R2008a