Time since state became active
elapsed( returns the length of time
that has elapsed since the associated state became active.
et is an alternative way to execute
Determine Time of State Activity
Store the number of seconds since the state became active.
en,du: y = elapsed(sec);
Display Elapsed Time
When the chart processes a broadcast of the event
E, transition out of the associated state and display the
elapsed time since the state became active.
In state and transition actions, you can use quotation marks to enclose the keyword
'sec'. For example,
elapsed('sec')is equivalent to
The Stateflow® chart resets the counter used by the
elapsedoperator 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 the
entryaction of state
In a Simulink model, the function call to
fexecutes in a single time step and does not contribute to the simulation time. After calling the function
f, the chart assigns a value of zero to
In a standalone chart, the function call to
fcan take several seconds of wall-clock time to complete. After calling the function
f, the chart assigns the nonzero time that has elapsed since state
Abecame active to
Introduced in R2017a