| Stateflow® | ![]() |
| On this page… |
|---|
Example of Counting Ticks to Store Input Data in a Buffer Array |
Count events when you want to keep track of explicit or implicit events in your chart.
You can count occurrences of explicit and implicit events using the temporalCount operator. For information about the syntax of this operator, see Using Temporal Logic in State Actions and Transitions.
Suppose you want to store input data in a buffer array during chart simulation, as shown below.

Initially, the chart awakens and remains in the Observe state, until the input data u is positive. Then, the transition to the state Collect_Data occurs.
After the state Collect_Data becomes active, the initial value of the input data u is assigned to the first element of the buffer array y. While this state is active, each subsequent value of u is assigned to successive elements of y using the temporalCount operator.
After 10 ticks, the data collection process ends, and the transition to the state Observe occurs. Just before the state Collect_Data becomes inactive, a function call to status displays the data collected in the buffer array.
![]() | Using Implicit Events | Best Practices for Using Events in Stateflow® Charts | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |