temporalCount

Control chart execution with the temporalCount operator

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.

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

This action counts and returns the integer number of ticks that have elapsed since activation of the state. Then, the action assigns to the variable y the value of the mm array whose index is the value that the temporalCount operator returns.

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

This action counts and returns the number of seconds that pass between activation and deactivation of the state.

ex: 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