Can you programmatically create a custom filter for Simulink model diffs?

5 views (last 30 days)
We have some blocks in our models that we basically always want to ignore when doing a model diff, and I have made a filter for that. But as of right now, the only way to get that to other people working on the models is to export the filters, and then they manually import the filters. It would be ideal if the filters could be setup progromatically, either through the project file, or some other method to edit the definition, that way everyone would always have the same base filters.
Anyone know where the filters are defined for the user? Can I get into the xml file somewhere?

Answers (1)

Ayush
Ayush on 18 Jun 2024
Hey Scott,
I understand that you are facing a challenge with distributing and synchronizing model comparison filters. You seek a method to programmatically establish these filters, ensuring consistent settings for model comparisons thus streamlining the proces.
One possible way can be creating the necessary comparison filter manually, locating the XML file where this filter is defined, and then writing a MATLAB script to distribute and apply this filter across different setups. This script can copy the predefined filter XML file to the appropriate directory on each user's machine. Here's how you could implement such a script:
function setupComparisonFilter(filterFileName, destinationFolder)
% Copy the filter file to the destination directory
% filterFileName is the path to the XML filter file you want to distribute
% destinationFolder is the target directory on the user's machine, typically within MATLAB's prefdir directory
% Example destinationFolder: fullfile(prefdir, 'ModelComparison', 'filters')
if ~exist(destinationFolder, 'dir')
mkdir(destinationFolder);
end
[filterFileFolder, filterBaseName, ext] = fileparts(filterFileName);
destinationFile = fullfile(destinationFolder, [filterBaseName, ext]);
% Copy the file
copyfile(filterFileName, destinationFile);
% Inform the user
fprintf('Filter file copied to: %s\n', destinationFile);
% Note: Additional steps may be required to set this filter as the default.
end
However this script assumes you have already created a filter and know the path to its XML file. It copies this filter to a specified directory, which should align with where MATLAB looks for these filters on startup.
For more information on 'prefdir' function and 'Simulink Model Comparision' , refer to the following MathWorks documentation links:
Hope this helps !
Regards
  1 Comment
Scott Tatum
Scott Tatum on 18 Jun 2024
I found the XML file in
fl = fullfile(getenv("APPDATA"),'MathWorks','MATLAB',"R"+string(version('-release')),'ComparisonCustomFilters.xml');
The trick that you can't just copy over the existing file is that it would destroy any other filters the user may have had, since the filter is in the user AppData folder.
I ended up writing a script to parse the existing filters, and merge in the filters that I created. This is just a lot of extra work that would be nice if it were integrated as part of the Project.

Sign in to comment.

Categories

Find more on Multicore Processor Targets in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!