Filter löschen
Filter löschen

Identifying ordinal position of an enumerated value

1 Ansicht (letzte 30 Tage)
Jim Johnson
Jim Johnson am 24 Okt. 2011
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 Kommentare
Jim Johnson
Jim Johnson am 24 Okt. 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 am 19 Jan. 2012
Use
length(enumeration('BasicColors'))
ans =
3

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by