How do I list values of the Simulink Enumeration definitions ?

81 views (last 30 days)
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','')
This returns an array of Entry ebjects.
After this command when I run
It returns and displays values as part of 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.
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.

Accepted Answer

riccardo on 8 Oct 2020
Edited: riccardo on 8 Oct 2020
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.
riccardo on 14 Oct 2020
using enumeration you extract the arrays of enumerated objects and labels :
>> [ gg, hh ] = enumeration( 'tryEnum01' )
gg =
4×1 tryEnum01 enumeration array
hh =
4×1 cell array
now gg is an array of enumerated objects including their numerical values
scalar-expanding the array within a "double" call:
>> indexes = double( gg(:) )
indexes =
and you can make use of "methods" and "properties" on members of gg: only the list of methods is populated and useful

Sign in to comment.

More Answers (1)

Amjad Elshenawy
Amjad Elshenawy on 23 May 2019
Hello Ozan
Although it is not a direct answer to your question, I see that the following post may be helpful
  1 Comment
Eric Bender
Eric Bender on 10 Jul 2020
I have the same question as Ozan. I have Simulink enumerations loaded in my workspace using the command:
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!