Export sldd to base workspace and get all entries

92 次查看(过去 30 天)
Hello, How to export entries present in simulink data dictionary to base workspace or in var in 2016 version following code is working for 2014
hDict = Simulink.dd.open([dict_name,'.sldd']);
childNamesList = hDict.getChildNames('Global');
for n = 1:numel(childNamesList)
assignin('base',childNamesList{n},hDict.getEntry(['Global.',childNamesList{n}]));
end

回答(1 个)

Donn Shull
Donn Shull 2017-8-10
The method you show for 2014 uses an undocumented internal API which is subject to change without notice. Beginning with release R2015a there is a documented API for accessing Simulink Data Dictionaries. One way to implement the code you have shown using the documented API would be:
hDict = Simulink.data.dictionary.open([dict_name,'.sldd']);
hDesignData = hDict.getSection('Global');
childNamesList = hDesignData.evalin('who');
for n = 1:numel(childNamesList)
hEntry = hDesignData.getEntry(childNamesList{n});
assignin('base', hEntry.Name, hEntry.getValue);
end
  2 个评论
Sabarirajan
Sabarirajan 2020-7-19
I want to export SLDD to Excel, is there any way ?
How to get the Object class type (prameter / Simulink) for workspace or from SLDD (Object)
SL CHEN
SL CHEN 2024-11-21,3:22
Thanks a lot, Donn, you have really helped me.
And Sabarirajan, this is what I do to export SLDD to Excel
% 指定 SLDD 文件路径
dict_name = 'myNewDictionary'
hDict = Simulink.data.dictionary.open([dict_name,'.sldd']);
section_name = 'DesignData';
hDesignData = hDict.getSection('Global');
childNamesList = hDesignData.evalin('who');
% 创建一个 cell 数组来存储所有的数据
data = cell(length(childNamesList), 2);
name_cell = repmat({''}, length(childNamesList), 1);
value_cell = repmat({''}, length(childNamesList), 1);
obj_type_cell = repmat({''}, length(childNamesList), 1);
DataType_cell = repmat({''}, length(childNamesList), 1);
StorageClass_cell = repmat({''}, length(childNamesList), 1);
HeaderFile_cell = repmat({''}, length(childNamesList), 1);
DefinitionFile_cell = repmat({''}, length(childNamesList), 1);
Dimensions_cell = repmat({''}, length(childNamesList), 1);
for n = 1:numel(childNamesList)
hEntry = hDesignData.getEntry(childNamesList{n});
% 存储条目名称和值到 cell 数组中
data{n, 1} = hEntry.Name;
data{n, 2} = hEntry.getValue;
name_cell{n} = hEntry.Name;
obj = data{n,2};
if strcmp(class(obj),'Simulink.Bus')
% do nothing
else
if strcmp(class(obj),'Simulink.Parameter')
if strcmp(obj.DataType,'single')
value_cell{n} = sprintf('%f ',obj.Value);
else
value_cell{n} = sprintf('%d ',obj.Value);
end
HeaderFile_cell{n} = obj.CoderInfo.CustomAttributes.HeaderFile;
DefinitionFile_cell{n} = obj.CoderInfo.CustomAttributes.DefinitionFile;
end
DataType_cell{n} = obj.DataType;
StorageClass_cell{n} = obj.CoderInfo.StorageClass;
Dimensions_cell{n} = sprintf('%d ',obj.Dimensions);
end
obj_type_cell{n} = class(obj);
end
tb = table(name_cell, obj_type_cell,DataType_cell,value_cell,StorageClass_cell,HeaderFile_cell,DefinitionFile_cell,Dimensions_cell);
% 将数据写入 Excel 表格
writetable(tb,'outputTB.xlsx','AutoFitWidth',false)

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by