Export sldd to base workspace and get all entries

67 ビュー (過去 30 日間)
Vinit
Vinit 2016 年 10 月 28 日
コメント済み: SL 2024 年 11 月 21 日
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
SL 2024 年 11 月 21 日
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)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by