Main Content

Comparison Tool

Diff and merge changes between Simulink models

Description

The Comparison Tool in Simulink® is an interactive tool for visualizing and merging differences between two Simulink models.

In a collaborative environment, you typically compare models:

  • When you require a peer review of your changes

  • Before you share or submit a version of your code to source control

  • When you want to pinpoint when an issue was introduced

  • When you want to examine your own local changes in detail

Using the Comparison Tool, you can:

  • Compare and review changes in SLX and MDL model files from any version of Simulink. If needed, the Comparison Tool resaves the models in the current release using the SLX format before opening the comparison report.

  • Visualize and highlight changes in the Simulink Editor.

  • Export the comparison results to send for peer review.

  • Use merge mode to port or restore changes in different models.

Simulink Model Comparison Tool

Open the Comparison Tool

You can select files and folders on disk to compare using one of these methods:

  • MATLAB® Home tab — In the File section, click Compare. Then, select the models you want to compare.

  • Current Folder browser or Project Files browser — To compare a model to another model on disk, right-click the selected model file and select Compare Against. Alternatively, select and right-click two model files, and then select Compare Selected Files/Folders.

  • Simulink Editor — To compare a model that is open in the Editor to another model on disk, on the Modeling tab, in the Evaluate & Manage section, click Compare To.

  • Command Window — Use the visdiff function.

For models under source control, you can open the Comparison Tool to understand differences between revisions using one of the following methods.

  • Current Folder browser or Project Files browser — To compare a model to its ancestor or to a different revision, right-click the model file and select Source Control > Compare to Ancestor or Source Control > Compare to Revision.

  • Branch Browser — To inspect changes in a model between two Git™ revisions, open the Branch Browser, right-click and select Source Control > Branches. In the right pane of the Branch Browser, right-click a model and select Show Difference.

    Branch Browser with two selected commits in the left pane and Show Difference context menu option in the right pane.

Examples

expand all

  • To simplify the comparison report and focus on a subset of changes, use built-in filters or create new custom filters.

    To create custom filters:

    1. In the Comparison toolstrip, click New Filter.

    2. Fill the Name field.

    3. In the Rules section, populate the Select, Parameter Name, and Parameter Value columns depending on the purpose of the filter.

      PurposeSet Select ColumnSet Parameter NameSet Parameter 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
      • Filter out annotation changes.

      • Filter out Inport and Outport block changes.

      • Filter out sample time parameter changes.

When you compare Simulink models, you can manipulate the comparison report at the command line by specifying an output argument.

Compare two model files and return a comparison object.

comparison = visdiff(modelname1,modelname2);

You can disable all filters from the model comparison report.

filter(comparison,"unfiltered");

To publish a comparison report to a file, use publish on the comparison object. The default format of the published report is HTML. publish saves the file in the current folder as filename1_filename2.html.

file = publish(comparison);
web(file)

Create a PDF comparison report named myreport. Save the report to the comparisonresults folder.

file = publish(comparison,format="PDF",Name="myreport",OutputFolder="comparisonresults");
web(file)

Supported report formats are HTML, PDF, and DOCX.

For instructions on how you can use visdiff to generate reports in your continuous integration workflows, see Attach Model Comparison Report to GitHub Pull Requests.

Related Examples

Parameters

expand all

Navigate between differences in the model comparison report.

Swap sides of the two models being compared and run the comparison analysis again.

By default, the Comparison Tool uses alphabetical ordering to place the models in the Left and Right panes. To view the full path of a file, expand the Show file details down arrow next to each filename.

Down arrows next to the model names in the Left and Right panes

When the models are not up to date, save or discard changes in the modified models and click Refresh to run the comparison analysis again.

Opens the Find dialog box where you can search for items in the comparison report.

Enabling Linked Scrolling synchronizes the scrolling between the Left and Right models.

Tip

If the report contains items that moved location from one model to another and they appear in very different parts of the comparison report, clear Linked Scrolling to make viewing these changes easier.

Click Highlight Now to highlight the currently selected comparison report node in the models in the Simulink Editor or in the model Configuration Parameters dialog box.

By default, the two models being compared display to the right of the comparison report, with the model corresponding to the left side of the report on top and the model corresponding to the right side appearing below. Clear Always Highlight to use the Highlight Now button and control highlighting in the models.

By default, the report shows changes to signal lines. Clear the Lines filter to simplify the report if needed.

By default, the report hides nonfunctional changes, such as repositioning of items, label positions, font and color settings for blocks and lines, and system print and display settings. Turn off filters to explore all differences, including nonfunctional changes.

Note

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.

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.

By default, the report hides block default parameters. Block defaults rarely change and cause longer reports when there are added or deleted blocks. Hiding block defaults can simplify the report.

Enable Block Defaults to explore differences including block default parameters.

Create custom filters to simplify the comparison report and focus on items of interest.

Save your comparison results in a printable report (HTML, WORD, PDF) or as a workspace variable.

Clicking Merge Mode opens a third pane called Target. The pane provides option buttons to allow you to pick changes from Left and Right models to save in the Target file.

Programmatic Use

expand all

visdiff("mymodel.slx","yourmodel.slx") opens the Comparison Tool from the MATLAB Command Window.

Limitations

MATLAB Online™ does not support creating custom filters in model comparison reports.

More About

expand all

Algorithms

To match items between one Simulink model and another, the Comparison Tool uses a heuristic algorithm that relies on various model properties, including block and line connectivity, location, and parameters. A heuristic algorithm decreases the cost of computationally expensive model comparison analysis by proposing a match that balances efficiency and accuracy.

Note

The analysis might not be able to detect matches between previously corresponding sections of files that have diverged.

Version History

Introduced in R2008b