使用枚举编写并仿真基本颜色序列图
此示例展示了如何编写和仿真包含数据类型 Simulink.IntEnumType 的变量的序列图。
定义 BasicColors.m 枚举
创建一个名为 BasicColors 的 enumeration 类。将 Red(0)、Yellow(1) 和 Blue(2) 定义为枚举值。
classdef BasicColors < Simulink.IntEnumType enumeration Red(0) Yellow(1) Blue(2) end
打开枚举示例模型
打开包含实现 EnumExample.slx 枚举的序列图的 BasicColors 架构模型。
model = systemcomposer.openModel("EnumExample");
要检查 Stateflow® Chart (Stateflow) 模块,请双击 source 组件。

输出数据端口 data 在此状态图中由枚举 BasicColors 类型化,随着模型的仿真,颜色从 Red 变为 Yellow。
打开枚举序列图
要打开 架构视图库 并访问 EnumSequenceDiagram 序列图,请转到建模 > 序列图。要仿真序列图,请点击运行。

由于 inEnum 目标端口从 1 枚举中继承了 BasicColors 的值,表明从 Red (0) 更改为 Yellow (1),因此序列图成功执行。