Documentation

Compare and Merge Simulink Models Containing Stateflow

This example shows you how to use the Simulink® Model Comparison to compare two Simulink models. You can view and merge the Simulink and Stateflow® differences in the resulting report.

This example shows you how to use the Simulink Model Comparison to understand what has changed between two different designs. Some development work has 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 for exploring and merging the differences.

Compare The Models

Setup the example files by running the following command.

slxmlcomp.internal.examples.setupStateflowExample();
% Then use visdiff to compare the models.
visdiff('slxml_sfcar_1', 'slxml_sfcar_2');

Understand The 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 items), inserted (blue items), or deleted (yellow items).

Stepping Through Differences

Use the "Next" and "Previous" navigation buttons on the Comparison tab to step through groups of changes in the report. When you do this to select an item:

  • The report highlights the corresponding item in the other tree (if it exists)

  • Both models display next to the report. The report highlights the corresponding item in the Simulink model, if possible.

You can control highlighting in the highlight toolstrip section.

Highlight Differences in the Simulink Models

Click to select the tree node "Out1" in the right hand side tree. Observe the report highlights "Out1" in the report, and the corresponding block in the model "slxml_sfcar_2".

Highlight Differences in a Stateflow Chart

Now 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

It is possible to control the type of changes the comparison report is displaying by using filters. To see the available filters, and whether or not they have been applied to the current report, click the Filter button in the filter toolstrip section.

For example, some information in the Simulink Model is defined as being "nonfunctional". These are changes that are unlikely to change the behavior of the design. Nonfunctional items are hidden by default and they can be shown by deselecting the 'Hide Nonfunctional Changes' item in the 'Filters' toolstrip menu dropdown.

Merge Changes in Models Containing Stateflow

You can merge the changes between the two Simulink & Stateflow models by clicking the 'Merge' button in the toolstrip. This creates a third file, 'targetFile', which can contain the changes from either the left model or right model. To select which changes you would like in the target file use the radio buttons in the right of the report.

Once you have selected the changes you want in the target model you can save these changes over the right model (slxml_sfcar_2) using the 'Save File' toolstrip button.

Note that in order for the tool to automatically connect merged transitions, you must merge states and junctions before transitions.

Further Information

'toolbox','simulink','helptargets.map'),'compareslxmlfiles') Compare Simulink Models

displayEndOfDemoMessage(mfilename);
Was this topic helpful?