
How to create simulink Data dictionary by using a command in a matlab script ?
5 views (last 30 days)
Show older comments
I have a Simulink Model block with some entries and outputs.Each Input and output has its Data types.
Apart from this i have an array where in one column i have all the input and output names and on one side i have its corresponding data types (all stored in an array).
From only these data how do i create a simulink data dictionary . How do i choose only this section from the array and create a data dictionary out of it .
For example : 'MyDataDictionary.sldd' containing a column named 'Names' and the next column named 'DataTypes' and all these saved in an sldd format 5all inside amatlab script) .
I want it like an automated script without going into simulink model explorer and then getting the data dictionary.
Any help will be appreciated .
0 Comments
Answers (1)
Rajanya
on 31 Jan 2025
You can leverage MATLAB's APIs for creating and adding entries to a data dictionary programmatically. The functions and their usages are given in detail in the documentation link - https://www.mathworks.com/help/simulink/ug/store-data-in-dictionary-programmatically.html
Here's an example script I created for demonstration purposes:
names = {'Input1', 'Input2', 'Output1', 'Output2'};
dataTypes = {'double', 'int32', 'single', 'boolean'};
dataTable = table(names', dataTypes', 'VariableNames', {'Names', 'DataTypes'});
% a table to store the data in mentioned format - Names and Data Types
dataDictionaryName = 'MyDataDictionary.sldd';
Simulink.data.dictionary.create(dataDictionaryName);
dictObj = Simulink.data.dictionary.open(dataDictionaryName);
sectionObj = getSection(dictObj, 'Design Data');
for i = 1:height(dataTable) % Loop to iterate over the table and add entries to the design data
entryName = dataTable.Names{i};
entryDataType = dataTable.DataTypes{i};
parameter = Simulink.Parameter;
parameter.DataType = entryDataType;
addEntry(sectionObj, entryName, parameter);
end
saveChanges(dictObj);
On executing the script, a data dictionary gets created as shown:

I hope this answers your question. Thanks!
0 Comments
See Also
Categories
Find more on Interactive Model Editing 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!