| Contents | Index |
| On this page… |
|---|
Comparing two versions of the same file is a common workflow when using Configuration Management tools. If your Configuration Management tool is configurable, you can customize your Diff operations on .mdl files from your Configuration Management tool to call the XML comparison functionality in the Simulink Report Generator. This allows you to compare two versions of the XML exported from the same .mdl file and generate a report of the differences.
TortoiseSVN and Subversion are a popular suite of open-source version control tools. The following example describes how to configure TortoiseSVN to use the Simulink Report Generator XML comparison. You can register the XML comparison function with TortoiseSVN as an extension-specific diff program to use for .mdl files. When you perform a TortoiseSVN diff on a .mdl file, TortoiseSVN uses the XML comparison to generate a report. This workflow describes a typical usage of Subversion on a Windows® PC.
There are two steps:
Create and save a MATLAB function file_comparison_driver that opens the Comparison Tool and invokes the XML comparison function for .mdl files. For an example, see Example file_comparison_driver Code.
Configure TortoiseSVN to use the file_comparison_driver function for .mdl files.
Optionally, you can also configure TortoiseSVN to use the same function to call the MATLAB Comparison Tool for .mat files and for Simulink manifest files (.smf files).
Create and save a MATLAB function that invokes the Comparison Tool as follows:
Use the example code to create your file comparison function. Copy the code in the section Example file_comparison_driver Code into a new file in the MATLAB Editor.
Save the file as file_comparison_driver.m.
Make sure the file is on the MATLAB path.
Test your function by calling it within MATLAB with two model files. For example:
file_comparison_driver( which('f14.mdl'),which('f14c.mdl') )This example is compatible with Release 2008b+ onwards and was tested with Subversion 1.6.2 on Windows XP.
Configure TortoiseSVN to use the XML comparison tool for .mdl files, as follows:
Right-click a file in Windows Explorer and select TortoiseSVN > Settings.
In the TortoiseSVN Settings dialog box, click Diff Viewer under External Programs in the tree, then click the Advanced button.
In the Advanced Diff settings dialog box, add an entry to specify what to do with .mdl files.
Click Add.
In the Add extension specific diff program dialog box, enter .mdl for the Extension and enter the following command in the External Program edit box:
"matlabroot\bin\matlab.exe" -r file_comparison_driver("'%base'","'%mine'") -nosplashReplace matlabroot with the path to the specific location on your computer for your MATLAB installation, for example, C:\Program files\MATLAB\R2009a.
The following example shows this setup on an Release 2009a installation.

Click OK to apply your changes and close all the Tortoise SVN dialog boxes.
If you also want to use the MATLAB Comparison Tool for .mat files and for Simulink manifest files (.smf files) you can repeat the steps to add exactly the same External Program command for .mat files and .smf files.
To test your setup, follow these steps:
Start MATLAB and open, modify, and save a Simulink model that is managed in a Subversion archive. This creates a local working copy that is different to the head repository copy.
In Windows Explorer, right-click your modified file, and select TortoiseSVN > Diff.
TortoiseSVN runs a new instance of MATLAB. MATLAB loads and runs the file_comparison_driver.m file. The file_comparison_driver function performs these steps:
Creates temporary copies of the current working version of the Simulink model and the previously stored version of the model.
Exports XML text files from both models.
Compares the XML text files and generates a comparison report displayed in the MATLAB Comparison Tool.
The function must preprocess the file names by creating renamed temporary copies because Subversion uses a temporary file naming convention that is not compatible with Simulink because of invalid delimiting characters. The branch and version information is embedded in the temporary model names. See also Compare XML Files from Models with Identical Names for information about using the report and a warning to avoid losing work in the temporary models.
Other TortoiseSVN workflows using Diff operations are also supported, such as comparing two versions in an archive.
Use the following example code to create your file comparison function, as described in Create file_comparison_driver Function.
function file_comparison_driver(base, mine)
%FILE_COMPARISON_DRIVER
%
%
% Use this function to call the MATLAB Comparison Tool
% from external tools such as the diff
% function of Subversion.
% If you have Simulink Report Generator version 3.5 or later
% installed, then the XML Comparison feature is called if you
% use this function with .mdl files.
%
% Typical use:
% "c:\matlab\R2009a\bin\matlab.exe" -r file_comparison_driver
% ("'%base'","'%mine'") -nosplash
%
% This example is compatible with Release 2008b+ onwards and
% was tested with Subversion 1.6.2 on Windows XP Professional.
% Copyright 2008-2012 The MathWorks, Inc.
% Confirm inputs:
error(nargchk(2, 2, nargin, 'struct'))
% Uncomment the following line if using a release before R2009b.
% slxmlcomp.register;
% Create a new temporary folder:
new_folder = tempname;
mkdir(new_folder)
% Create a temporary copy of the base file that uses a
% valid MATLAB file name:
new_base = create_temp_locations(base, new_folder);
new_mine = create_temp_locations(mine, new_folder);
% Use "visdiff" function to open MATLAB Comparison Tool:
visdiff(new_base, new_mine)
end
% -----------------------------------------------
function new = create_temp_locations(old, new_dir)
% Names may have unsupported characters due to Subversion
% conventions. Change them to underscores.
[~, old_name, ext] = fileparts(old);
new_name = replace_unsupported_characters(old_name);
% If no characters needed replacing then there is no
% need to create a temporary copy
if strcmp(old_name,new_name)
new = old;
return
end
% Create new target location for this file:
new = fullfile(new_dir, [new_name ext]);
% Copy files to the temporary location:
ok = copyfile(old, new, 'f');
assert(ok, 'Failed to copy files to temporary location');
end
% ------------------------------------------------
function new = replace_unsupported_characters(old)
firstLetterIndex = regexp(old,'[a-z_A-Z]','start','once');
new = old(firstLetterIndex:end);
new = strrep(new,'.','_');
new = strrep(new,'-','_');
end
![]() | Export, Print, and Save XML Comparison Results | Component Reference | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |