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.
Create a working copy of the example files. MATLAB® copies the files to an example folder so that you can edit them.
A user made some changes to the model
sl_aircraft1 and saved the resulting model as
visdiff to compare the
The Comparison Tool shows a report that only includes the differences between the two models, not the complete model hierarchies.
Colors indicate if items have been modified (purple), inserted (blue), or deleted (yellow).
Stepping 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. The report highlights the selected items in both Simulink models if it is possible.
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.
You can control the type of changes displayed in the comparison report by applying filters. To see the available filters and whether or not they are applied to the current report, on the Comparison tab, in the Filter section, click the down arrow to expand the filter gallery. Click filter names to toggle whether they are applied. In the Filter section, click Show or Hide to control how the filters are applied.
For example, some information in the Simulink model file is defined as being nonfunctional. These are changes that are unlikely to change the behavior of the design. Nonfunctional items are hidden by default. You can show them by deselecting the Nonfunctional Changes button when the Hide filter button is selected.
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
Click the Save File button to save the changes you selected over the right model (
Tip: Merge blocks before lines, and merge states and junctions before merging transitions. See Merging Tips.