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 CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by