Main Content

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.

Comparing Models

Create a working copy of the example files. MATLAB® copies the files to an example folder so that you can edit them.

slcomparisons.examples.simulinkMerge;

A user made some changes to the model sl_aircraft1 and saved the resulting model as sl_aircraft2.

Use visdiff to compare the sl_aircraft1 and sl_aircraft2 models.

visdiff('sl_aircraft1', 'sl_aircraft2');

Understanding Results

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.

Filtering Results

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.

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 File button to save the changes you selected over the right model (sl_aircraft2).

Merging tips

You must merge blocks before lines in the Simulink part of the report. You must merge states and junctions before merging transitions, or the report cannot make the connections.

For information on merging between models with identical names, see Comparing Models with Identical Names.

See Also

visdiff

Further Information

Compare Simulink Models

Comparing Models with Identical Names

Related Examples

Compare and Merge Simulink Models Containing Stateflow

Resolve Conflicts with Simulink Three-Way Merge