Identifying ordinal position of an enumerated value

6 ビュー (過去 30 日間)
Jim Johnson
Jim Johnson 2011 年 10 月 24 日
is there a function, enum_ordinal for instance that returns an ordinal position of the enuerated value in the enumerated type?
classdef WeekDays
enumeration
Monday, Tuesday, Wednesday, Thursday, Friday
end
end
temp=enum_ordinal(Tuesday)
temp = 2
  3 件のコメント
Jim Johnson
Jim Johnson 2011 年 10 月 24 日
Actually I am using enumerated types in StateFlow and use the following to create the enumerated type
Simulink.defineIntEnumType('BasicColors', ...
{'Red', 'Yellow', 'Blue'}, [0;1;2],...
'AddClassNameToEnumNames', true);
I can find the value of an enumeration
BasicColors.Yellow == BasicColors(1)
ans =
1
but no way to determine the number of enumerations, in this case it should be 3 but size doesn't work just returns the length of the string 'BasicColors'
size BasicColors
ans =
1 11
Any help out there, the help in Matlab seems to be lacking here?
If I could find the number of enumeration values I could loop thru them looking for a match.
Jim Johnson
Jim Johnson 2012 年 1 月 19 日
Use
length(enumeration('BasicColors'))
ans =
3

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeDecision Logic についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by