필터 지우기
필터 지우기

Identifying ordinal position of an enumerated value

조회 수: 1 (최근 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 CenterFile Exchange에서 Complex Logic에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by