Main Content

visdiff

Compare two files or folders

Description

visdiff(filename1,filename2) opens the Comparison Tool and displays the differences between the two files or folders. The Comparison Tool supports MATLAB® code files, zip files, MAT files, and various other MATLAB and Simulink® file formats. For a complete list, see Input Arguments.

Use visdiff to compare two Simulink models, identify changes, and merge differences. For more information, see Model Comparison (Simulink).

example

visdiff(filename1,filename2,type) compares two files using the specified comparison type. If you do not specify a type, visdiff uses the default comparison type for your selected files. You can use this syntax to compare files only.

example

comparison = visdiff(___) compares two files and returns a comparison object that contains the differences between the specified files. Use the comparison object to manipulate the comparison at the command line, for example by applying filters and publishing comparison reports. This syntax does not open the Comparison Tool and does not require a display. It is particularly useful for automating the creation of comparison reports for continuous integration (CI) workflows. This syntax does not support all file types. Supported files include Simulink models, requirement and link set files, plain text files, MATLAB scripts, MATLAB apps, and text-based source code files.

example

Examples

collapse all

This example shows how to compare two files using relative and full paths.

Compare the two files lengthofline.m and lengthofline2.m in the current folder.

visdiff("lengthofline.m","lengthofline2.m")

Compare the two MAT files gatlin.mat and gatlin2.mat using a fully qualified file name.

visdiff(fullfile(pwd,"supportingFiles","mymatFiles","gatlin.mat"), ...
fullfile(pwd,"supportingFiles","mymatFiles","gatlin2.mat"))
ans = 
  Setting 'comparisons.folder.IncludeSubfolders' with properties:

          ActiveValue: 1
       TemporaryValue: <no value>
        PersonalValue: <no value>
    InstallationValue: <no value>
         FactoryValue: 1

Compare the two files lengthofline.m and lengthofline2.m as binary.

If you do not specify the comparison type, visdiff compares the two files using the default text comparison type. By changing to the binary comparison type you can examine differences such as end-of-line characters.

visdiff("lengthofline.m","lengthofline2.m","binary")

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 (Simulink).

Input Arguments

collapse all

File or folder name, specified as a character vector or string. filename can include a relative path to the current folder or a full path.

This table shows the supported file types.

File TypeFile Extension
MATLAB
MATLAB code file.m
MATLAB live code file.mlx, .m (since R2025a)
Plain textAny
Text-based source code.c, .cpp, .java, etc.
MATLAB App.mlapp
BinaryAny
Folder 
ZIP file.zip
MATLAB figure.fig
MAT-file.mat
Project definition files.xml
Project archive.mlproj
Dependency GraphML.graphml
Simulink
Simulink models.slx, .mdl
Simulink model template.sltx
Simulink project template.sltx
Simulink data dictionary.sldd
Other products
Requirements Toolbox™.slreqx. For more information, see Create and Save Printable Reports of Comparison Results (Requirements Toolbox)
Requirements Toolbox links.slmx. For more information, see Create and Save Printable Reports of Comparison Results (Requirements Toolbox)
Simulink Test™.mldatx
SimBiology® models.sbproj
System Composer® models.slx
Simscape® files.ssc

You can also use the Comparison Tool for basic comparisons for many other file extensions including .prj, .req, .cvf, .wrl, .x3s, .ssc, .xml, and .tlc.

Comparison type, specified as "text" or "binary". Some comparisons do not support all of the comparison types. If you specify a comparison type that is not supported, MATLAB displays an error.

To examine differences such as end-of-line characters in text files, specify the "binary" comparison type.

Output Arguments

collapse all

Comparison object for manipulating the comparison at the command line, for example, by applying filters and publishing comparison reports. Supported files include Simulink models, plain text files, MATLAB scripts, MATLAB apps, and text-based source code files.

Limitations

  • In MATLAB Online™, the Comparison Tool does not support all file types. Supported file types include text files, MATLAB code files, folders, zip files, and Simulink models.

Alternative Functionality

You can open the Comparison Tool interactively.

  • MATLAB editors — Open a file in the MATLAB Editor or in the Live Editor. In the Editor or Live Editor toolstrip, select Compare > Compare To. Then, select the file you want to compare to.

    You can also compare a file with the autosave version or the saved version on disk. In the Editor tab, select Compare > Compare to Version on Disk or Compare to Backup. If your file is modified, the Editor saves the file before comparing. The Compare to Version on Disk and Compare to Backup options are only available if the option for automatically saving changes to a file is disabled. To disable the option, go to the Home tab, and in the Environment section, click Settings. Then, select Editor/Debugger and clear Save changes upon clicking away from a file. This option is not available in the Live Editor.

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

  • Files or Project panel — To compare two files on disk, select both files. Then, right-click and select Compare Selected Files/Folders. The Comparison Tool opens the file you select first on the left.

Version History

Introduced in R2008b

expand all