Main Content

elapsed,et

Time since state became active

Syntax

Description

example

elapsed(sec)returns the length of time that has elapsed since the associated state became active.

example

etis an alternative way to executeelapsed(sec).

Note

The expressionselapsed(sec)andetare equivalent totemporalCount(sec).

Examples

expand all

商店the number of seconds since the state became active.

en,du: y = elapsed(sec);

Stateflow chart that uses the elapsed operator in a state.

When the chart processes a broadcast of the eventE, transition out of the associated state and display the elapsed time since the state became active.

E{disp(et);}

Stateflow chart that uses the et keyword in a transition.

Tips

  • In state and transition actions, you can use quotation marks to enclose the keyword'sec'. For example,elapsed('sec')相当于elapsed(sec).

  • The Stateflow®chart resets the counter used by theelapsedoperator each time the associated state reactivates.

  • The timing for absolute-time temporal logic operators depends on the type of Stateflow chart:

    • Charts in a Simulink®model define temporal logic in terms of simulation time.

    • Standalone charts in MATLAB®define temporal logic in terms of wall-clock time.

    The difference in timing can affect the behavior of a chart. For example, suppose that this chart is executing theentryaction of stateA.

    Stateflow chart with one state. The entry action in state A calls a function f and stores the elapsed time in y.

    • In a Simulink model, the function call tofexecutes in a single time step and does not contribute to the simulation time. After calling the functionf, the chart assigns a value of zero toy.

    • In a standalone chart, the function call tofcan take several seconds of wall-clock time to complete. After calling the functionf, the chart assigns the nonzero time that has elapsed since stateAbecame active toy.

版本History

Introduced in R2017a