Compare Simulink Models

Navigate the Simulink Model Comparison Report

You can compare models from any version of Simulink®. The comparison tool produces a comparison report based on the SLX files, resaved in the current version if necessary. Use the report to explore the differences, view the changes highlighted in the original models, and merge differences.

The Comparison report shows changes only, not the entire file contents. The report shows a hierarchical view of the portions of the files that differ, and does not show sections of the files that are identical. To learn about the report, see About Simulink Model Comparison.

To step through differences, on the Comparison tab, in the Navigate section, click Next or Previous. See Step Through Changes.

You can also click to select items in the hierarchical trees and observe the following display features:

  • Selected items appear highlighted in a box.

  • If the selected item is part of a matched pair it is highlighted in a box in both left and right trees.

  • When you select an item, the original model displays and the corresponding item is highlighted. See Explore Changes in the Original Models.

Report item highlighting indicates the nature of each difference as follows:

Type of report itemHighlightingNotes
ModifiedPurple

Modified items are matched pairs that differ between the two files. When you select a modified item it is highlighted in a box in both trees.
Changed parameters for the selected pair are displayed underneath.

InsertedBlue

When you select an unmatched item it is highlighted in a box in one tree only.

DeletedOrange
ContainerNone

Rows with no highlighting indicate a container item that contains other modified or unmatched items.

Icons indicate the category of item, for example: model, subsystem, Stateflow® machine or chart, block, line, parameter, etc.

To expand or filter the tree view, use the toolstrip for the following functions:

  • Filter — Use filters to show only the changes you are interested in. By default the report hides all nonfunctional changes, such as repositioning of items. Turn off filters to explore all differences including nonfunctional changes. See Filter Comparison Reports.

  • Find — Opens the Find dialog box where you can search for items.

  • If you want to swap the files, on the Comparison tab, select Swap. The report swaps the sides and reruns the comparison. Refresh also runs the analysis again.

To create a new report, see Select Simulink Models to Compare.

For examples with instructions, see also Examples of Model Comparison.

Step Through Changes

On the Comparison tab, in the Navigate section, when you click the Next arrow button (or press the Down key when the report has focus), you step through groups of changes in the report, in the following order:

  1. The first time you click Next, it selects the first changed (purple) or inserted (blue) node.

  2. Step through the differences with the Next button.

    • When selected items have a match in the right tree then they are also highlighted.

    • Next skips white nodes with no color background, if they have no parameter changes underneath. White nodes are parts of the hierarchy that contain no differences.

    • If there is an insertion or deletion with child nodes, Next skips the child nodes if they are all also insertions or deletions. For example, if you insert a subsystem, Next selects the top subsystem node, then skips all the nodes inside the subsystem (if they are all also insertions) and selects the next difference.

    • Next minimizes context switching when highlighting in models. When you click Next, the report steps through all differences at the same level of the model, subsystem, or chart, in both left and right trees in the report, before moving to the next level of the report. For example, you step through all differences in a subsystem in the left and right trees, before moving to another subsystem.

  3. When you have stepped through all changes, Next stops at the end.

If you click an item in the report, the Next/Previous controls will step through changes from the point you selected.

Explore Changes in the Original Models

When you compare Simulink models, you can choose to display the corresponding items in the original models when you select report items. You can use this highlighting function to explore the changes in the original models. When you select an item, the report highlights the corresponding item in the model.

Control the display by using the Highlight Now button and the Always Highlight check box.

For details, see Display Differences in Original Models.

Merge Differences

To merge, on the Comparison tab, click Merge Mode. The Target pane appears at the bottom of the report. Use the buttons to select differences to keep in the target. For more information, see Merge Simulink Models from the Comparison Report.

Open Child Comparison Reports for Selected Nodes

If additional comparisons are available for particular parameters, you see a Compare button to open a report for that pair of nodes. For example, if there are differences in the Model Workspace, you can click Compare to open a new report to explore differences in variables.

  • You can open a new comparison for parameters when the report cannot display all the details, e.g., long strings or a script.

  • If the original models contain MATLAB Function block components, and if differences are found, click the Compare button at the end of the MATLAB Function block report items to open new comparisons in the Comparison Tool, showing the text difference reports for the MATLAB Function block components. You can merge differences in MATLAB Function block code from the text comparison report. See Merge Simulink Models from the Comparison Report.

  • If the original models contain truth tables, and if differences are found:

    • Click the Compare button at the end of the MATLAB Function node to see a summary of all changes.

    • Click the truthtable node to reverse annotate and display both truth table editors.

    • Click the Compare button on the parameter to open a new text comparison showing only Condition table differences.

    • Similarly click the Compare button for Action Table to view only Action changes.

Understand the Report Hierarchy and Matching

Note

It might not be possible for the analysis to detect matches between previously corresponding sections of files that have diverged too much.

If you cannot see changes you expected to see in the report, turn off filters and see all identified changes. See Filter Comparison Reports.

Filter Comparison Reports

You can define custom filters to simplify reports and focus on specified elements. You can import and export filters for sharing. Use built-in filters to control display of categories of changes. Turn off filtering to view all identified changes.

To see the available filters, and whether or not they apply 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.

To define a new custom filter:

  1. On the Comparison tab, in the Filter section, click New Filter.

  2. In the New Filter dialog box, define one or more rules for your new filter. For example, you can select parameters or blocks of particular types or values. Suggested values depend on the items in your comparison report. Specify a unique name for your filter and click Apply.

  3. To check if your filter applies to the items you expect, enable only the new filter in the filter gallery and then click Show. This is often easier then checking that a filter is hiding the changes you expect to see in the report.

Observe how these custom filters are defined.

PurposeSelect ColumnParameter NameParameter Value
Filter out Annotation changesAnnotationClick the minus button to clear the row.Leave blank
Filter out Inport and Outport block changesBlockBlockTypeInport
To add a row, click Add Rule, then select BlockBlockTypeOutport
Filter out sample time parameter changesParameterSampleTimeAny

  • Annotation changes:

  • Inport and Outport block changes:

  • Sample time parameter changes:

To show all changes, use either of these methods:

  • Hide nothing – Click Hide and disable all filters in the gallery.

  • Show everything – Create a custom filter. In the New Filter dialog box, delete the contents of the first column so it shows Any, then remove the rest of the row under Parameter Name. Click Show and enable the "everything" filter in the gallery.

Use the filters to show only the changes you are interested in. By default the report hides all nonfunctional changes, such as repositioning of items. Turn off filters to explore all differences including nonfunctional changes. Try this if you cannot see changes you expected to see in the report.

Built-in filters include:

  • Lines. Select all changes to signal lines, including functional changes.

  • Nonfunctional Changes. The report identifies certain items in the model file as nonfunctional, for example, items representing parameters such as block, system, chart, or label positions; font and color settings for blocks and lines; and system print and display settings.

  • Block Defaults. Block defaults rarely change and cause longer reports when there are added or deleted blocks. Often the report is simpler when you hide block defaults.

Exceptions

The report does not filter out changes to Block and System names, annotations, and Stateflow Notes as nonfunctional, even though changes to these items do not affect the outcome of simulation. The report always displays these changes to facilitate review of code changes, because they can contain important information about users' intentions.

In rare cases, the report filters out changes that can impact the behavior of the design. By default, moves are filtered as nonfunctional, but in these cases moves can change design behavior:

  • Moving blocks can in some cases change the execution order.

  • In a Stateflow chart, if you move states or junctions so that they intersect, the model fails to simulate.

To view these types of changes in the report, turn off the filter for nonfunctional changes.

Change Color Preferences

You can change and save your diff color preferences for the Comparison tool. You can apply your color preferences to all comparison types.

  1. On the MATLAB® Home tab, click Preferences.

  2. In the Preferences dialog box, under MATLAB, click Comparison.

  3. Edit color settings as desired for differences and merges. View the colors in the Sample pane.

    The Active Settings list displays Default (modified).

  4. To use your modified settings in the comparison, click Apply and refresh the comparison report.

  5. To return to the default color settings, in the Preferences dialog box, click Reset and click Apply. Refresh the comparison report.

  6. If you want to save your modified color preferences for use in future MATLAB sessions, click Save As. Enter a name for your color settings profile and click OK.

    After saving settings, you can select them in the Active Settings list.

Save Comparison Results

To save your comparison results, use these Comparison tab buttons:

Alternatively, you can publish a comparison report to a file using the visdiff function.

Examples of Model Comparison

For examples with instructions, see:

See Also

Related Examples

More About