- Open or Create an SLDD: Open your existing SLDD or create a new one using the Simulink Data Dictionary Manager.
- Add Enum to SLDD: You can add the enumerated type to the SLDD by referencing the m-file. Here’s how you can do it programmatically:
How can I export all the enumerated data types from m-file to an SLDD (Data Dictionary)? Can Enum be created in m-file? IF yes what's the solution for this?
14 views (last 30 days)
Show older comments
Creating Enum definition in the m-file and exporting back to SLDD
0 Comments
Answers (2)
Manikanta Aditya
on 27 Dec 2024
Edited: Manikanta Aditya
on 29 Dec 2024
Yes, you can create enumerated data types (Enums) in an m-file and export them to an SLDD (Simulink Data Dictionary).
1.) Create a Enum in an m-file: Create a new m-file and define your enumeration class. For example, if you want to define days of the week, your m-file (e.g., WeekDays.m) would look like this:
classdef WeekDays
enumeration
Monday, Tuesday, Wednesday, Thursday, Friday
end
end
Refer to the following documentation to know more about enumation classes:
2.) Export Enum to SLDD:
% Load the SLDD
slddObj = Simulink.data.dictionary.open('yourDataDictionary.sldd');
% Get the section where you want to add the enum
dData = getSection(slddObj, 'Design Data');
% Add the enum type definition
addEnumType(dData, 'WeekDays', 'WeekDays.m');
Refer to the following documentation to know more about 'addEnumType':
3.) Save and Close the SLDD: After adding the enum, save and close the SLDD:
saveChanges(slddObj);
close(slddObj);
I hope this helps you.
3 Comments
Manikanta Aditya
on 2 Jan 2025
It looks like you're encountering an issue with the addEnumType function. This function was introduced in MATLAB R2023b and is used to add enumerated data types to the Architectural Data section of a Simulink data dictionary.
Please ensure that you are using MATLAB R2023b or later, as the addEnumType function is not available in earlier versions
Josh Kahn
on 6 Jan 2025
You can use importEnumTypes to move your class-defined enumerations to data dictionary entries. The enum class must be defined as a Simulink.IntEnumType. I included an example below for you. Let us know if you run into any other issues!
Regards,
Josh
enumFlightPhases.m
classdef enumFlightPhases < Simulink.IntEnumType
enumeration
Undefined (-1)
Taxi (1)
TakeOff (2)
Climb (3)
Cruise (4)
Descent (5)
Approach (6)
Land (7)
end
end
saveEnumToDD.m
% Save the enumeration to the data dictionary
ddFileName = 'MyDataDictionary.sldd';
if ~exist(ddFileName, 'file')
dd = Simulink.data.dictionary.create(ddFileName);
else
dd = Simulink.data.dictionary.open(ddFileName);
end
importEnumTypes(dd,{'enumFlightPhases'})
saveChanges(dd)
close(dd)
See Also
Categories
Find more on Manage Design Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!