Documentation

About Simulink Model Comparison

Creating Model Comparison Reports

In Simulink®, you can compare Simulink models.

You can use models from any version of Simulink. Use the comparison report to explore the differences, view the changes highlighted in the original models, and merge differences.

You can access the comparison tool from:

  • The MATLAB® Current Folder browser context menu

  • The MATLAB Comparison Tool

  • The MATLAB command line

  • The Simulink Editor Analysis menu

  • The Simulink Project view

You can use the comparison tool with both model file formats, SLX and MDL. If the selected files are .mdl files, or SLX files saved in a previous version, then the comparison tool first exports the .mdl files to SLX files in a temporary directory, and produces a comparison report based on the SLX files.

For more information on creating reports, see Select Simulink Models to Compare.

Examples of Model Comparison

For examples with instructions, see:

For more information on using and understanding the comparison reports, see Compare Simulink Models.

Using Model Comparison Reports

You can display comparison reports in the Comparison Tool. In the interactive report, you can click items in the report to display the corresponding items highlighted in the original models.

The comparison report shows a hierarchical view of the portions of the two files that differ. The report does not show sections of the files that are identical.

If the files are identical you see a message reporting there are no differences.

If files have not been saved, you see an error message informing you that you must save modified or newly created models before running a comparison.

Note

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

Change detection is based on a scoring algorithm. Items match if their score is above a threshold. The tool's algorithm uses a comparison pattern that defines the thresholds assigned to particular node types (e.g., block).

For more information on using the report, see Compare Simulink Models.

To control highlighting, see Display Differences in Original Models.

To merge differences, see Merge Simulink Models from the Comparison Report.

For more information about the Comparison Tool, see Comparing Files and Folders (MATLAB).

Select Simulink Models to Compare

To learn what you can do with comparison reports, see About Simulink Model Comparison.

Select Files from the Simulink Editor

To compare files using the Simulink Editor:

  1. Select Analysis > Compare To....

    The Select Files or Folders for Comparison dialog box opens.

  2. If the Editor currently displays a model, the current model name and path appear automatically selected in the First file or folder edit box. Use the browse buttons to locate and select files for the first and second model files.

  3. When you click Compare, the comparison tool performs the analysis, and displays the resulting report in the Comparison Tool.

Select Files from the Current Folder Browser

To compare two files from the Current Folder browser:

  • For two files in the same view, select two files, right-click and select Compare Selected Files/Folders.

  • Alternatively, you can browse to select the second file to compare:

    1. Select a file, right-click and select Compare Against

    2. Select the second file to compare in the Select Files or Folders for Comparison dialog box.

    3. Leave the default Comparison type, Simulink XML text comparison.

    4. Click Compare.

For more information about comparisons of other file types (e.g., text, MAT, or binary) with the Comparison Tool, see Comparing Files and Folders (MATLAB).

Select Files from a Simulink Project

If you have a Simulink Project using source control, you can create a model comparison report from the Modified Files view of the Simulink Project Tool. For details, see Project Management.

Select Files from the Comparison Tool

To compare files using the Comparison Tool, from the MATLAB Toolstrip, in the File section, select the Compare button. In the dialog box select files to compare.

Select Files from the Command Line

To compare XML files from the command line, enter

visdiff(filename1, filename2)

where filename1 and filename1 are XML files or Simulink models.

visdiff produces a report in the Comparison Tool.

To create an xmlcomp.Edits object at the command line without opening the Comparison Tool, enter:

Edits = slxmlcomp.compare(modelname_A,modelname_B) 
See Export Results to the Workspace for information about the xmlcomp.Edits object.

Choose a Comparison Type

To change comparison type, either create a new comparison from the Comparison Tool, or use the Compare Against option from the Current Folder browser. You can change comparison type in the Select Files or Folders for Comparison dialog box. For example, if you want the MATLAB text differences report for XML or model files, change the comparison type to Text comparison in the dialog before clicking Compare. Alternatively, see the visdiff function.

Related Topics

Was this topic helpful?