matlab脚本对simulink数据字典(sldd)的操作-间歇汇总

手动选择文件:

% select .xx file,xx替换为所需格式,文件路径字符串存于DDFile变量中
[xxfile,~,~] = uigetfile('*.xx','Select xx file');
if xxFile == 0
    return;
end

 

sldd to .m

% open .sldd file 
MyDictObj = Simulink.data.dictionary.open('sldd file path');
% export data dictionary entries to mat or matlab file
DataSectObj = getSection(MyDictObj,'Design Data');
% 导出到'file name.m'文件中
exportToFile(DataSectObj,'file name.m');

 

.m to sldd

% open .sldd file 
MyDictObj = Simulink.data.dictionary.open('[sldd file path]');
% export data dictionary entries to mat or matlab file
DataSectObj = getSection(MyDictObj,'Design Data');

 %导入sldd

ImportedVars = importFromFile(DataSectObj,'[yourfile].m','existingVarsAction','overwrite');
saveChanges(MyDictObj)

 

修改sldd中数据的属性,批量修改某属性

使用到的函数/方法:

  • getSection

  • getEntry

  • find

  • getValue

  • setValue

 

% open .sldd file 
 MyDictObj = Simulink.data.dictionary.open("[sldd file path]");
% export data dictionary entries to mat or matlab file
 dDataSectObj = getSection(MyDictObj,'Design Data');
signal_objects = find(dDataSectObj,'-value','-class','simulink.Signal');
for i = 1:numel(signal_objects)
    signal_obj = signal_objects(i);
    Obj = getEntry(dDataSectObj,signal_obj.Name);
    % 设置信号属性
    a=Obj.getValue;
    a.CoderInfo.StorageClass="Custom";
    a.CoderInfo.CustomStorageClass = 'Default';
    Obj.setValue(a);
    clear("a");
end

 

posted @ 2023-10-13 11:12  cynety  阅读(2032)  评论(0编辑  收藏  举报