Main Content

Compare and Merge Simulink Models Containing Stateflow

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 containing Stateflow® using the comparison report. A Stateflow license is required to run this example.

Compare 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.stateflowMerge;

A user added a new kickdown mode to the shift_logic. You can use the Simulink Model Comparison to compare the two models and produce a report to explore and merge the differences.

Use visdiff to compare the sl_sfcar_1 and sl_sfcar_2 models.

visdiff('sl_sfcar_1','sl_sfcar_2');

Understand 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.

Highlight Differences in the Simulink Models

Select the tree node Out1 in the Right tree. Observe the report highlights Out1 in the report, and the corresponding block in the model sl_sfcar_2.

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.

Highlight Differences in a Stateflow Chart

Browse down the tree to locate the Stateflow charts in the report. Observe the Stateflow chart icon next to the shift_logic node. Click kickdown in the Right tree. The report displays both shift_logic Stateflow charts. Observe where the new kickdown functionality has been added to one of the charts.

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.

Merge Changes in Models Containing Stateflow

You can merge the changes between the two Simulink and Stateflow 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 or right model. 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_sfcar_2).

Tip: Merge blocks before lines, and merge states and junctions before merging transitions. See Merging Tips.

See Also

visdiff

Further Information

Compare Simulink Models

Comparing Models with Identical Names

Related Examples

Compare and Merge Simulink Models

Resolve Conflicts with Simulink Three-Way Merge