How do I list values of the Simulink Enumeration definitions ?

So I am trying to write a script to parse the .sldd format of simulink data dictionary.
I need to get all the possible values of an enumeration type as string.
I can list enum type definitions by:
enumTypeDefs = find(sectionObj, '-value','-class','Simulink.data.dictionary.EnumTypeDefinition')
This returns an array of Entry ebjects.
After this command when I run
getValue(enumTypeDefs(1))
It returns and displays values as part of Simulink.data.dictionary.EnumTypeDefinition class object.
I took a look at the documentation and saw that there isn't a property or method that returns all the values, you can return default value etc. but not all of them. https://nl.mathworks.com/help/simulink/slref/simulink.data.dictionary.enumtypedefinition-class.html
Also there isn't a method to return the number of elements in the enumeration type, this makes me unable to iterate over and return values one by one since I don't know the boundry of the iteration index.
I'd be glad If someone helped.
Thanks.

 채택된 답변

riccardo
riccardo 2020년 10월 8일
편집: riccardo 2020년 10월 8일

1 개 추천

I don't know if it's still an open Q, but since i found it while looking for the same thing, here's how I did it.
Once you have the Entry objects, get their Value with getValue, this/these will be EnumTypedefinition object(s).
Then one of the properties of an EnumTypeDefinition object is "Enumerals", hence:
enumDefList = <enumTypeDefObject>.Enumerals
will return a structure array holding Name, Value and Description of the enumerated type.
I'm using 2020a at the moment.

댓글 수: 5

Hi Riccardo, was your answer directed to Ozan or myself? I'm using Matlab 2014b and using the following syntax to create my enumerations doesn't seem to work with what you had specified for my issue.
Simulink.defineIntEnumType('epb_parkbrakeswitch_SL_T', 'PB_SWITCH_NEUTRAL','PB_SWITCH_UP','PB_SWITCH_DOWN'},[2,4,6]);
Ozan Yüksel
Ozan Yüksel 2020년 10월 9일
편집: Ozan Yüksel 2020년 10월 13일
Hello, as this is a really old issue, I'm kind of blurry on the solution but I remember solving this and the key information being the convertibility of Simulink Enum type objects to matlab enumertaions using enumeration() function.
The answer was more for the OP, apparently I've managed to append it to the following thread ... LOL!
In general, when you have a well-defined class you can use "methods" and "properties" calls to investigate the interface.
@Eric
Ozan's suggestion should work for you : using the "enumeration" call, with various options
Simulink.defineIntEnumType( 'tryEnum01', { 'AA', 'BB', 'CC', 'KK' }, [0, 2 , 4, 6] )
>>
enumeration tryEnum01
Enumeration members for class 'tryEnum01':
AA
BB
CC
KK
>>
@Ozan
using the Entry property you can get hold of the entire structure array, including numerical representation of the enumerated list.
Eric Bender
Eric Bender 2020년 10월 13일
편집: Eric Bender 2020년 10월 13일
@Riccardo
Thanks for the feedback. I was already familiar with the enumeration tryEnum01 command but I'm still unclear as to how to get the numerical representations of enum names from definition you've given above. Specifically I'd love to be able to get the full range of numerical values without having to cycle through each enum name (e.g. commandXYZ for tryEnum01 would yield : [0, 2 , 4, 6].
Thanks,
Eric
@Eric
using enumeration you extract the arrays of enumerated objects and labels :
>> [ gg, hh ] = enumeration( 'tryEnum01' )
gg =
4×1 tryEnum01 enumeration array
AA
BB
CC
KK
hh =
4×1 cell array
{'AA'}
{'BB'}
{'CC'}
{'KK'}
<<
now gg is an array of enumerated objects including their numerical values
scalar-expanding the array within a "double" call:
>> indexes = double( gg(:) )
indexes =
0
2
4
6
<<
and you can make use of "methods" and "properties" on members of gg: only the list of methods is populated and useful

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Amjad Elshenawy
Amjad Elshenawy 2019년 5월 23일

0 개 추천

Hello Ozan
Although it is not a direct answer to your question, I see that the following post may be helpful

댓글 수: 1

I have the same question as Ozan. I have Simulink enumerations loaded in my workspace using the command:
Simulink.defineIntEnumType('epb_parkbrakeswitch_SL_T',{'PB_SWITCH_NEUTRAL','PB_SWITCH_UP','PB_SWITCH_DOWN'},[2,4,6]);
I have other scripts that run which are able to get the names of the loaded enumeration classes and even the enumeration members for the class. However how can I programatically access the values [2,4,6]? I need this for other purposes and I can't seem to figure out how to have those returned to me upon inspection.
Thank you.

댓글을 달려면 로그인하십시오.

카테고리

질문:

2019년 4월 2일

댓글:

2020년 10월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by