Missed blocks between two models

1 vue (au cours des 30 derniers jours)
Praveen Kumar
Praveen Kumar le 26 Avr 2024
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

Réponses (1)

Namnendra
Namnendra le 15 Juil 2024
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.

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by