Identifying ordinal position of an enumerated value

3 views (last 30 days)
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 Comments
Jim Johnson
Jim Johnson on 24 Oct 2011
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 on 19 Jan 2012
Use
length(enumeration('BasicColors'))
ans =
3

Sign in to comment.

Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!