How to compare between simulink setting file?
    조회 수: 8 (최근 30일)
  
       이전 댓글 표시
    
How to compare between simulink setting file
visdiff command is not what i wanted..
댓글 수: 1
  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?
채택된 답변
  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: 
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Foundation and Custom Domains에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!