Sum of enumerated data types

1 回表示 (過去 30 日間)
A VP
A VP 2019 年 6 月 3 日
編集済み: Matt J 2019 年 6 月 3 日
I have an array of 50 elements all of which are enum types. (say FALSE(0), TRUE(1), UNAVAILABLE(2)). I would like to calculate the sum of the array elements. The function 'SUM' in matlab does not support enumerated datatypes. I tried using a 'for' loop and did something like this :
value = 0;
for i = 1:50
value = value + array(i);
end
But I receive an error saying code generation does not support binary operations on enums.
Is there a better way to implement this logic?

回答 (1 件)

Matt J
Matt J 2019 年 6 月 3 日
編集済み: Matt J 2019 年 6 月 3 日
Is the enumeration a subclass of a numeric type? If so, what if you pre-convert to that type?
value = sum(uint32(array))

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by