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
---2026更新
对Simulink.data.dictionary.Section类型有以下操作方法,可通过调用函数或直接对section类型操作:
addEntry |
Add new entry to data dictionary section |
assignin |
Assign value to data dictionary entry |
deleteEntry |
Delete data dictionary entry |
evalin |
Evaluate MATLAB expression in data dictionary section |
exist |
Check existence of data dictionary entry |
exportToFile |
Export data dictionary entries from section to MAT-file or MATLAB file |
find |
Search in data dictionary section |
getEntry |
Create Simulink.data.dictionary.Entry object to represent data dictionary entry |
importFromFile |
Import variables from MAT-file or MATLAB file to data dictionary section |
% 写入SLDD:同名自动覆盖 if ~desData.exist(param_name) addEntry(desData, param_name, param_obj);%函数方式 fprintf('写入字典:%s\n',param_name); else desData.assignin(param_name,param_obj);%调用方法 fprintf('更新字典:%s\n',param_name); end
本文来自博客园,作者:cynety,转载请注明原文链接:https://www.cnblogs.com/connection0x00/p/17761094.html

浙公网安备 33010602011771号