Compare two files or folders
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.
visdiff to compare two Simulink models, identify changes, and merge differences. For more information,
see Model Comparison (Simulink).
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.
comparison = visdiff(___)
Compare Two Files
This example shows how to compare two files using relative and full paths.
Compare the two files
lengthofline2.m in the current folder.
Compare the two MAT files
gatlin2.mat using a fully qualified file name.
visdiff(fullfile(pwd,"supportingFiles","mymatFiles","gatlin.mat"), ... fullfile(pwd,"supportingFiles","mymatFiles","gatlin2.mat"))
Compare Two Files and Specify Type
Compare the two files
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.
Publish Comparison Report
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.
To publish a comparison report to a file, use
on the comparison object. The default format of the published report is
publish saves the file in the current folder as
file = publish(comparison); web(file)
Create a PDF comparison report named
Save the report to the
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
generate reports in your continuous integration workflows, see Simulink Model Comparison for GitHub Pull Requests (Simulink).
filename — File or folder name
character vector | string
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 Type||File Extension|
|Text-based source code|
|Project definition files|
|Simulink model template|
|Simulink project template|
|Simulink data dictionary|
|Requirements Toolbox links|
|System Composer® models|
You can also use the Comparison Tool for basic comparisons for many other
file extensions including
type — Comparison type
Comparison type, specified as
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,
"binary" comparison type.
The default comparison type for XML files depends on the XML type, and is
"xml" to override the
default comparison type for the file.
comparison — Comparison object
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.
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.
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 HistoryIntroduced in R2008b
R2023b: Publish comparison reports for MATLAB apps
Starting in R2023b, you can return a comparison object when you compare MATLAB apps. Use the comparison object to publish comparison reports programmatically.
R2023a: Publish comparison reports for plain text, MATLAB scripts, and text-based source code
Starting in R2023a, you can return a comparison object when you compare plain text files, MATLAB scripts, and text-based source code files. Use the comparison object to publish comparison reports programmatically.
R2023a: XML comparison type will be removed in a future release
XML comparison type will be removed in a future release. Overriding the default
comparison type by specifying
"xml" will not be possible in a
future release. In R2023a, scripts that use
visdiff(filename1,filename2,"xml") continue to work.
- Compare Files and Folders and Merge Files
- Model Comparison (Simulink)
- Simulink Model Comparison for GitHub Pull Requests (Simulink)
- Compare and Merge Requirement Sets Using Comparison Tool (Requirements Toolbox)