Contents

Count Events

When to Count Events

Count events when you want to keep track of explicit or implicit events in your chart.

How to Count Events

You can count occurrences of explicit and implicit events using the temporalCount operator. For information about the syntax of this operator, see Operators for Event-Based Temporal Logic.

Collect and Store Input Data in a Vector

The following modelmodel collects and stores input data in a vector during chart simulation:

The chart contains two states and one MATLAB® function:

Stage 1: Observation of Input Data

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.

Stage 2: Storage of Input Data

After the state Collect_Data becomes active, the value of the input data u is assigned to the first element of the vector y. While this state is active, each subsequent value of u is assigned to successive elements of y using the temporalCount operator.

Stage 3: Display of Data Stored in the Vector

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 vector data at the MATLAB prompt.

For more information about ticks in a Stateflow® chart, see Control Chart Execution Using Implicit Events.

Was this topic helpful?