About Simulink Model Comparison
Creating Model Comparison Reports
In Simulink®, you can compare Simulink models. Review and merge differences using three-way model merge or two-way model merge.
You can use models from any version of Simulink. Use the comparison report to explore the differences, view the changes highlighted in the original models, and merge differences.
For details, see Compare Simulink Models and Merge Simulink Models from the Comparison Report.
You can access the comparison tool from:
The MATLAB® Current Folder browser context menu
The MATLAB Comparison Tool
The MATLAB command line
The Simulink Editor Compare To menu
The Project view
You can use the comparison tool with both model file formats, SLX and MDL. If the selected files are MDL files, or SLX files saved in a previous version, then the comparison tool first exports the MDL files to SLX files in a temporary folder, and produces a comparison report based on the SLX files.
For more information on creating reports, see Select Simulink Models to Compare.
Examples of Model Comparison
For examples with instructions, see:
For more information on using and understanding the comparison reports, see Compare Simulink Models.
Using Model Comparison Reports
You can display comparison reports in the Comparison Tool. In the interactive report, you can click items in the report to display the corresponding items highlighted in the original models.
The comparison report shows a hierarchical view of the portions of the two files that differ. The report does not show sections of the files that are identical.
If the files are identical you see a message reporting there are no differences.
If files have not been saved, you see an error message informing you that you must save modified or newly created models before running a comparison.
Note
It might not be possible for the analysis to detect matches between previously corresponding sections of files that have diverged too much.
Change detection is based on a scoring algorithm. Items match if their score is above a threshold. The tool's algorithm uses a comparison pattern that defines the thresholds assigned to particular node types (e.g., block).
For more information on using the report, see Compare Simulink Models.
To control highlighting, see Display Differences in Original Models.
To merge differences, see Merge Simulink Models from the Comparison Report.
For more information about the Comparison Tool, see Compare Files and Folders and Merge Files.
Select Simulink Models to Compare
To learn what you can do with comparison reports, see About Simulink Model Comparison.
Compare Files from the Simulink Editor
To compare files from within the Simulink Editor:
Open one of the models you want to compare.
On the Modeling tab, in the Evaluate & Manage section, click Compare To.
Locate and select the model file you want to compare to.
Click Open.
The Comparison Tool performs a comparison between the opened model and the model you selected.
Select Files from the Current Folder Browser
To compare two files from the Current Folder browser:
For two files in the same view, select two files, right-click and select Compare Selected Files/Folders.
Alternatively, you can browse to select the second file to compare:
Select a file, right-click and select Compare Against
Select the second file to compare in the Select Files or Folders for Comparison dialog box.
For models, leave the default Comparison type,
Simulink Model Comparison
.Click Compare.
For more information about comparisons of other file types (e.g., text, MAT, or binary) with the Comparison Tool, see Compare Files and Folders and Merge Files.
Select Files from a Project
If you have a project using source control, you can create a model comparison report from the Modified Files view of the project. For details, see Project Management.
Select Files from the Comparison Tool
To compare files using the Comparison Tool, from the MATLAB Toolstrip, in the File section, select the Compare button. In the dialog box select files to compare.
Select Files from the Command Line
To compare XML files from the command line, enter
visdiff(filename1, filename2)
where filename1
and filename2
are XML files or
Simulink models.
visdiff
produces a report in the Comparison Tool.
To create an xmlcomp.Edits
object at the command line without
opening the Comparison Tool,
enter:
Edits = slxmlcomp.compare(modelname_A,modelname_B)
xmlcomp.Edits
object.Choose a Comparison Type
To change comparison type, either create a new comparison from the Comparison Tool, or
use the Compare Against option from the Current Folder browser.
You can change comparison type in the Select Files or Folders for Comparison dialog box.
For example, if you want the MATLAB text differences report for XML or model files, change the comparison type
to Text comparison
in the dialog before clicking
Compare. Alternatively, see the visdiff
function.