필터 지우기
필터 지우기

Missed blocks between two models

조회 수: 7 (최근 30일)
Praveen Kumar
Praveen Kumar 2024년 4월 26일
답변: Namnendra 2024년 7월 15일 17:18
Hi,
I would like to know how to find the added deleted and modified blocks between two models using external custom filter
Thanks in advance please find the attached file

답변 (1개)

Namnendra
Namnendra 2024년 7월 15일 17:18
Hi Praveen,
To compare two Simulink models and identify added, deleted, and modified blocks, you can use MATLAB's Simulink Report Generator, which includes a Model Comparison tool. This tool can generate a detailed report of the differences between two models. However, if you want to use an external custom filter to process the comparison results, you can follow these steps:
Step 1: Use Model Comparison Tool
First, use the built-in Model Comparison tool to compare the two models and generate a comparison report.
% Load the two models
model1 = 'model1';
model2 = 'model2';
load_system(model1);
load_system(model2);
% Perform the comparison
comparison = visdiff(model1, model2);
% Save the comparison results
save('comparisonResults.mat', 'comparison');
Step 2: Extract Comparison Results
Extract the comparison results and process them using your custom filter.
% Load the comparison results
load('comparisonResults.mat', 'comparison');
% Get the list of differences
differences = comparison.Differences;
% Initialize lists for added, deleted, and modified blocks
addedBlocks = {};
deletedBlocks = {};
modifiedBlocks = {};
% Process the differences
for i = 1:length(differences)
diff = differences(i);
switch diff.Type
case 'add'
addedBlocks{end+1} = diff.Object;
case 'delete'
deletedBlocks{end+1} = diff.Object;
case 'modify'
modifiedBlocks{end+1} = diff.Object;
end
end
% Apply custom filter to the lists
addedBlocks = customFilter(addedBlocks);
deletedBlocks = customFilter(deletedBlocks);
modifiedBlocks = customFilter(modifiedBlocks);
% Display the results
disp('Added Blocks:');
disp(addedBlocks);
disp('Deleted Blocks:');
disp(deletedBlocks);
disp('Modified Blocks:');
disp(modifiedBlocks);
Step 3: Define Custom Filter
Define your custom filter function to process the lists of added, deleted, and modified blocks.
function filteredList = customFilter(blockList)
% Example custom filter: Remove blocks with specific names
filterOutNames = {'BlockNameToRemove1', 'BlockNameToRemove2'};
filteredList = {};
for i = 1:length(blockList)
block = blockList{i};
blockName = get_param(block, 'Name');
if ~ismember(blockName, filterOutNames)
filteredList{end+1} = block;
end
end
end
Summary
1. Use the Model Comparison Tool to compare the two models and generate a comparison report.
2. Extract the comparison results and categorize the differences into added, deleted, and modified blocks.
3. Apply your custom filter to process the lists of added, deleted, and modified blocks.
This approach allows you to leverage MATLAB's built-in tools for model comparison while applying your custom logic to filter and process the results.
I hope above information helps you.
Thank you.

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by