Compare and Merge Simulink Models
This example shows how to use the comparison report in MATLAB® to understand what has changed between two different designs. It shows how to view and merge the changes between two Simulink® models from the comparison report.
Compare Models
A user made some changes to the model sl_aircraft1
and saved the resulting model as sl_aircraft2
. To compare the model files, in the Files panel, select the two files. Right-click either file and select Compare Selected Files/Folders.
Alternatively, use visdiff
to compare the sl_aircraft1
and sl_aircraft2
models.
visdiff('sl_aircraft1.slx','sl_aircraft2.slx');
Understand Results
The Comparison Tool shows a report that only includes the differences between the two models, not the complete model hierarchies.
The report colors the modified items in purple, the inserted items in blue, and the deleted items in yellow.
Step Through Differences
Use the Next and Previous navigation buttons on the Comparison tab to step through groups of changes in the report:
The report goes through the changes one by one. If the selected item in the Left tree has a match, it will also be selected in the Right tree.
MATLAB displays both models next to the report. If possible, the report highlights the selected items in both Simulink models.
To control highlighting in models, on the Comparison tab, in the Highlight section, select or clear the check box Always Highlight. You can click the Highlight Now button to highlight the currently selected report node at any time.
Filter Results
By default, the Comparison Tool hides nonfunctional changes, such as repositioning of items, label positions, font and color settings for blocks and lines, and system print and display settings.
To simplify the comparison report and focus on a subset of changes, use the Quick Filters pane. In the toolstrip, in the Filter section, click Filter.
You can also hide all model elements of a certain type by right-clicking on the element in the report.
You can save the current filter selection to share or reuse. For more information, see Filter Comparison Report Using Quick Filters.
Publish Results
To save a printable version of a model comparison report, select Publish > HTML, Word, or PDF.
Merge Changes in Simulink Models
You can merge the changes between the two Simulink models by clicking the Merge Mode button in the toolstrip. This creates a third file, targetFile
, which can contain the changes from either the left model (sl_aircraft1
) or right model (sl_aircraft2
). Use the buttons in the Target tree to select the differences to keep in the targetFile
.
Click the Save Result button to save the changes you selected over the right model (sl_aircraft2
).
Tip: Merge blocks before lines, and merge states and junctions before merging transitions. See Recommended Merge Order in Models.
See Also
Related Examples
Review Changes in Simulink Models