Main Content

duration

Time during which condition is valid

Description

example

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).

example

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

Note

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

Examples

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.

en,du:
   y = duration(x>5,msec);

Stateflow chart that uses the duration operator in a state.

Tips

  • 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.

Introduced in R2017a