Main Content


Time during which condition is valid



duration(C,time_unit) returns the length of time that has elapsed since the conditional expression C became true and the associated state became active. Specify time in seconds (sec), milliseconds (msec), or microseconds (usec).


duration(C) is an alternative way to execute duration(C,sec).


The temporal logic operator duration is not supported in standalone charts in MATLAB®.


expand all

Transition out of the state when the variable x has been greater than or equal to 0 for longer than 0.1 seconds.

[duration(x>=0) > 0.1]

Stateflow chart that uses the duration operator in a transition.

Store the number of milliseconds since the variable x became greater than 5 and the state became active.

   y = duration(x>5,msec);

Stateflow chart that uses the duration operator in a state.


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

  • The Stateflow® chart resets the value of the duration operator if the conditional expression C becomes false or if the associated state becomes inactive.

  • The duration operator does not support conditions that depend on local or output structures. For more information, see Access Bus Signals Through Stateflow Structures.

Version History

Introduced in R2017a