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?

26 views (last 30 days)
Creating Enum definition in the m-file and exporting back to SLDD

Answers (1)

Manikanta Aditya
Manikanta Aditya on 27 Dec 2024 at 14:59
Edited: Manikanta Aditya on 29 Dec 2024 at 13:10
Hello @Parambrahma,
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:
  1. Open or Create an SLDD: Open your existing SLDD or create a new one using the Simulink Data Dictionary Manager.
  2. 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:
% 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.
  2 Comments
Parambrahma
Parambrahma ongeveer 16 uur ago
>> slddObj = Simulink.data.dictionary.open('Demo10.sldd');
>> dData = getSection(slddObj, 'Design Data');
>> addEnumType(dData, 'Lat_SLDD_Enum', 'Lat_SLDD_Enum.m');
Unrecognized function or variable 'addEnumType'.
Getting an error on 3rd line.
Could you please elaborate on this?
Manikanta Aditya
Manikanta Aditya ongeveer 15 uur ago
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

Sign in to comment.

Categories

Find more on System Composer in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!