How to compare between simulink setting file?

1 回表示 (過去 30 日間)
dayoung
dayoung 2024 年 6 月 27 日
回答済み: Tejas 2024 年 8 月 14 日
How to compare between simulink setting file
visdiff command is not what i wanted..
  1 件のコメント
Angelo Yeo
Angelo Yeo 2024 年 6 月 27 日
What do you mean by "visdiff is not what I wanted"?
What is your pain point on visdiff? Or what do you actually want?

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

回答 (1 件)

Tejas
Tejas 2024 年 8 月 14 日
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:

カテゴリ

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

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by