Main Content

duration

Time during which condition is valid

Description

time = duration(condition) returns the length of time, in seconds, that condition stays true. Use this operator in the Requirements Table block.

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.

Set a equal to 1 when the time that the input data u is greater than or equal to 0 exceeds the value of y. Otherwise, the block sets a equal to 0.

Requirements table using the duration operator in a precondition.

Input Arguments

expand all

Logical condition, specified as true or false. You can specify the value of condition by using an expression that evaluates to true or false. The operator evaluates condition at each time step.

condition does not support expressions that depend on local or output data.

Example: duration(u)

Example: duration(u>=0)

Data Types: logical

Units of time that duration returns, specified in seconds (sec), milliseconds (msec), or microseconds (usec).

Data Types: enumerated

Output Arguments

expand all

Length of time, in seconds, that condition stays true, returned as a scalar double.

Tips

  • The Requirements Table block resets the output of the duration operator if condition becomes false or if the block becomes inactive.