Main Content

temporalCount

事件数、图执行次数或自状态激活以来的时间

描述

示例

temporalCount(E) 返回自关联状态激活以来事件 E 的发生次数。

示例

temporalCount(tick) 返回自关联状态激活以来图唤醒的次数。

当 Simulink® 模型中的 Stateflow® 图有输入事件时,不支持隐式事件 tick

示例

temporalCount(time_unit) 返回自关联状态激活以来经过的时间长度。将 time_unit 指定为秒 (sec)、毫秒 (msec) 或微秒 (usec)。

注意

MATLAB® 中的独立 Stateflow 图仅支持将 temporalCount 用作绝对时间时序逻辑运算符。

示例

全部展开

每次图处理 E 事件的广播时,访问数组 M 的连续元素。

在 Simulink 模型的图中,输入:

on E: y = M(temporalCount(E));

Stateflow chart that uses the temporalCount operator in a state.

MATLAB 中的独立图不支持使用 temporalCount 作为基于事件的时序逻辑运算符。

将输入数据 u 的值存储在数组 M 的连续元素中。

在 Simulink 模型的图中,输入:

en,du:
   M(temporalCount(tick)+1) = u;

Stateflow chart that uses the temporalCount operator in a state.

MATLAB 中的独立图不支持使用 temporalCount 作为基于事件的时序逻辑运算符。

存储自状态激活以来的毫秒数。

en,du:
   y = temporalCount(msec);

Stateflow chart that uses the temporalCount operator in a state.

提示

  • 您可以使用引号将关键字 'tick''sec''msec''usec' 括起来。例如,temporalCount('tick') 等效于 temporalCount(tick)

  • 每当关联状态重新激活时,Stateflow 图都会重置 temporalCount 运算符使用的计数器。

  • 绝对时间时序逻辑运算符的计时取决于 Stateflow 图的类型:

    • Simulink 模型中的图根据仿真时间定义时序逻辑。

    • MATLAB 中的独立图根据挂钟时间定义时序逻辑。

    计时上的差异会影响图的行为。例如,假设此图正在执行状态 Aentry 动作。

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

    • 在 Simulink 模型中,对 f 的函数调用在单个时间步中执行,不会增加仿真时间。调用函数 f 后,图将零值赋给 y

    • 在独立图中,对 f 的函数调用可能需要几秒的挂钟时间才能完成。调用函数 f 后,图将状态 A 变为激活状态后经过的非零时间赋给 y

版本历史记录

在 R2008a 中推出