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
A user added a new kickdown
mode to the shift_logic
. Use the Comparison Tool to compare the two models and produce a report to explore and merge the differences. In the Files panel, select the two model files. Then, right-click either file and select Compare Selected Files/Folders.
Alternatively, 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.
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.
Highlight Differences in 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 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.
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.
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 Result 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 Recommended Merge Order in Models.
See Also
Related Examples
Review Changes in Simulink Models