Control chart execution with the count operator





The count(C) operator returns a double value equivalent to the number of ticks after the conditional expression, C, becomes true. The count operator is reset if the conditional expression becomes false. If the count operator is used within a state, it is reset when the state that contains it is entered. If the count operator is used on a transition, it is reset when the source state for that transition is entered.

The value for count is dependent on the step size. Changing the solver or step size for your Simulink® model affects the result of Stateflow® charts that include the count operator.

To ensure that your Stateflow chart simulates without error, do not use count with these objects:

  • Continuous time charts

  • Graphical, MATLAB®, or Simulink functions

  • Simulink based states

  • Transitions that can be reached from multiple states

  • Default transitions

Use the count operator in charts that use C or MATLAB as the action language.


expand all

The transition occurs when the value of data has been greater than or equal to 2 for longer than 5 ticks.

[count(data >= 2) > 5]

When the state is exited, x is set to the number of ticks that data has been greater than 5.

ex: x = count(data>5)

Introduced in R2019a