MATLAB: How to get the list of variables with enumerated data using classdef in a model

simulink

I would like to know how to find all variables using enumerated data in a model.
For example, I want to get all used enumerated data in a model like "Red", "Yellow", "Green" in the following image.

Best Answer

You can use the following codes in order to get all variables with enumerated types used in model blocks.
% Find all variables with enumerated types used in model blocks
usedTypesVars = Simulink.findVars('EnumsReporting','IncludeEnumTypes',true);
% Here, EnumsReporting is the name of the model and
% usedTypesVars is an array of Simulink.VariableUsage objects
% Find indices of enumerated types that are defined by MATLAB files or P-files
enumTypesFile = strcmp({usedTypesVars.SourceType},'MATLAB file');
% Find indices of enumerated types that are defined using the function
% Simulink.defineIntEnumType
enumTypesDynamic = strcmp({usedTypesVars.SourceType},'dynamic class');
% In one array, represent indices of both kinds of enumerated types
enumTypesIndex = enumTypesFile | enumTypesDynamic;
% Use logical indexing to return the names of used enumerated types
enumTypeNames = {usedTypesVars(enumTypesIndex).Name}'
You can see the above code in the following manual.
 
- Migrate Enumerated Types into Data Dictionary
http://www.mathworks.com/help/releases/R2015b/simulink/ug/migrate-enumerated-types-into-data-dictionary.html