simulink使用日志

这篇博客介绍了如何利用Excel管理Simulink模型的仿真变量逻辑,并详细阐述了Stateflow中after函数的用法,包括事件计数、chart计数和计时功能。通过案例展示了after函数在计时和计数中的应用,帮助读者理解如何在Simulink和Stateflow中实现精确的控制逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

选择之前编写好的用例,Excel用例格式遵循如下第一附图的格式
① 第一列为仿真步长时间,单位与simulink中设置一致,默认为s
② 第二列为对应时间下的数值,不允许出现中文注释以及表头等其它符号
③ 可以使用不同工作表管理模型需要仿真的变量,实例模型有两个输入和两个输出,所以Test Case 工作簿里一共4个工作表,分别对应两个输入及两个输出;
④ 模型仿真出来的数据可以导回到Excel中,所以建议使用Excel管理所有变量的逻辑关系(如下面第二附图为本人管理模型的逻辑表格)

旋转模块:选中模块后,右键“Rotate&Flip”。也可快捷键“Ctrl+R”

Stateflow_after计时计数

在Stateflow中可以使用after函数进行计时,计数等操作。具体使用方法可以参考Stateflow的帮助文档:《Stateflow User Guide》。

1 事件计数
语法:
after(n,E)

n是一个正整数或计算结果为正整数值的表达式。E是事件(event)。

Returns true if the event E has occurred at least n times since the associated state became active. Otherwise, the operator returns false.

2 chart计数
语法:
after(n,tick)

n is a positive integer or an expression that evaluates to a positive integer value.

Returns true if the chart has woken up at least n times since the associated state became active. Otherwise, the operator returns false.

The implicit event tick is not supported when a Stateflow chart in a Simulink model has input events. For more information, see “Control Chart Behavior by Using Implicit Events” on page 11-23.

3 计时
语法:
after(n,sec)
after(n,msec)
after(n,usec)

n is a positive real number or an expression that evaluates to a positive real value.

Returns true if at least n units of time have elapsed since the associated state became active. Otherwise, the operator returns
false.

In charts in a Simulink model, specify time in seconds (sec), milliseconds (msec), or microseconds (usec).

In standalone charts in MATLAB, specify time in seconds (sec). The operator creates a MATLAB timer object that generates an implicit event to wake up the chart. MATLAB timer objects are limited to 1 millisecond precision. For more information, see “Events in Standalone Charts” on page 3-53.

案例1:

 


c的输出结果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浮华蒲公英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值