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, 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"))

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 script.m
Live script.mlx
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", "binary", or "xml". 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.

The default comparison type for XML files depends on the XML type, and is either "text" or "xml". Specify "text" or "xml" to override the default comparison type for the file.

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 Home tab — In the File section, click Compare. Then select the files or folders to compare.

  • Current Folder browser — To compare a file or folder, right-click the selected file or folder and select Compare Against. To compare two files or folders, right-click the selected files or folders and select Compare Selected Files/Folders.

  • MATLAB Editor or Live Editor tabs — To compare a file that is open in the Editor, in the File section, click Compare.

  • MATLAB Editor tab — To compare a file with the autosave version or the saved version on disk, in the File section, expand Compare and select Compare with Version on Disk or Save and Compare with Autosave. If you modified the file, the Editor saves the file before comparing. The Compare with Version on Disk and Save and Compare with Autosave options are available only if you disable autosaving of changes. To do so, go to the Home tab, and in the Environment section, click Preferences. Then, select Editor/Debugger and clear Save changes upon clicking away from a file.

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

Version History

Introduced in R2008b

expand all