How to compare between simulink setting file?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How to compare between simulink setting file
visdiff command is not what i wanted..
1 Kommentar
Angelo Yeo
am 27 Jun. 2024
What do you mean by "visdiff is not what I wanted"?
What is your pain point on visdiff? Or what do you actually want?
Akzeptierte Antwort
Tejas
am 14 Aug. 2024
Hello Dayoung,
Here is a workaround to compare Simulink setting files without using the ‘visdiff’ function. It is assumed that your Simulink files produce a ‘Simulink.ConfigSet’ object, which contains configurations for the Simulink models. Below is an example to demonstrate how two such ‘Simulink.ConfigSet’ objects can be compared:
- Convert the ‘Simulink.ConfigSet’ object into a structure.
structure1 = getConfigSetAsStruct(configSet1);
structure2 = getConfigSetAsStruct(configSet2);
function settingsStruct = getConfigSetAsStruct(configSet)
% Get the names of configuration
paramNames = get_param(configSet, 'ObjectParameters');
% Create a structure
settingsStruct = struct();
% Loop through each configuration and add it to the structure
for paramName = fieldnames(paramNames)'
paramNameStr = paramName{1};
paramValue = get_param(configSet, paramNameStr);
settingsStruct.(paramNameStr) = paramValue;
end
end
- Create a structure named ‘differences’ to store any differences found between the settings files.
differences = struct();
- Check for configurations that are only present in either of the setting files.
% Get the names of configuration from both the structures
fields1 = fieldnames(structure1);
fields2 = fieldnames(structure2);
% Check for fields that are only in first structure
onlyIn1 = setdiff(fields1, fields2);
if ~isempty(onlyIn1)
differences.onlyIn1 = onlyIn1;
end
% Check for fields that are only in second structure
onlyIn2 = setdiff(fields2, fields1);
if ~isempty(onlyIn2)
differences.onlyIn2 = onlyIn2;
end
- Check for configurations that are present in both files but have different values.
% Check for fields that are common, but differ in values
commonFields = intersect(fields1, fields2);
for i = 1:length(commonFields)
field = commonFields{i};
if ~isequal(structure1.(field), structure2.(field))
differences.(field) = struct('settings1', structure1.(field), 'settings2', structure2.(field));
end
end
- In the end, the ‘differences’ structure will store the discrepancies found in the two Simulink setting files.
Refer to the documentation below for a better understanding of the solution:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Foundation and Custom Domains finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!