【发布时间】:2022-08-15 23:10:32
【问题描述】:
我觉得这在 C# 中非常容易,但在 Simulink 中是不可能的。我正在尝试使用枚举值作为数组索引。诀窍是:我有一个根据枚举中元素数量调整大小的数组,但它们的值是不连续的。所以我希望定义的枚举和 Simulink 代码读取 A(4) 处的值。显然,它将改为读取 A(999)。有什么方法可以得到我正在寻找的行为?
classdef Example < Simulink.IntEnumType
enumeration
value1 (1)
value2 (2)
value13 (13)
value999 (999)
end
end
// Below in Simulink; reputation is not good enough to post images.
A = Data Store Memory
A.InitialValue = uint16(zeros(1, length(enumeration(\'Example\'))))
// Do a Data Store Read with Indexing enabled; Index Option = Index vector (dialog)
A(Example.value999)
-
将枚举转换为整数的数据类型转换怎么样?
-
使用 \"Data Type Conversion\" 或 \"Cast\" 块将枚举转换为整数将为您提供整数的数值。所以: const(Example.value999) --> cast(uint16) --> display(999),而我想要的是 display(4)。
标签: matlab vector indexing simulink enumeration