Compare two files or folders
displays the differences between the two specified files or folders in the
Comparison Tool. The File Comparison Tool supports many file types such as
MATLAB® code files, zip files, MAT-files, and various other MATLAB and Simulink® file formats. For a more complete list, see Input Arguments.
visdiff to compare two Simulink models and identify changes or merge differences between the models.
For more information, see Model Comparison (Simulink).
compares two model files and returns a comparison object containing the differences
between the two files. This syntax does not open the Comparison Tool and is only
supported for comparing Simulink models.
be model files. Use the comparison object to manipulate the comparison at the
command line, for example by applying filters and publishing comparison
Compare Two Files
Compare two files using both relative and full paths.
Compare the two files
lengthofline2.m in the current folder.
Compare the two demo files
gatlin2.mat using a fully qualified file name.
visdiff(fullfile(matlabroot,'toolbox','matlab','demos','gatlin.mat'), ... fullfile(matlabroot,'toolbox','matlab','demos','gatlin2.mat'))
Compare Two Files and Specify Type
Compare the two files
lengthofline2.m as binary.
If you do not specify 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 comparing Simulink models, you can manipulate the comparison at the command line by
specifying an output argument to
Compare two model files and get the comparison object output from
comparison = visdiff(modelname1,modelname2);
(Optional) Filter the comparison result. Supported filters are:
'unfiltered' – removes all filtering from the
'default' – default filtering strategy for
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)
To specify options for the report, use the following name-value pairs with
'Format'– The file format of the published report.
'html'(default) – single-file HTML document,
'docx'– Microsoft® Word document, or
'pdf' – PDF document.
'Name'– The name of the report.
A character vector or scalar string array. If you specify a file extension, then
'OutputFolder'– Where to save the report.
A character vector or scalar string array. The default is the current folder.
Alternatively, you can specify the name-value pairs in an
name — File or folder name
character vector | string
File or folder name to compare, specified as a character vector or string.
name can include a relative path, but the relative
path must be in the current folder. Otherwise,
include a full path.
The following table summarizes the list of supported files.
|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 an unsupported
comparison type is specified, 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. Only supported for comparing Simulink models.
In MATLAB Online™, the File Comparison Tool does not support all file types. Supported file types include text files, MATLAB code files, folders, zip files, and Simulink models.
In some cases, there might be multiple comparison types available for your selection
(e.g., text, binary, or file list). To select a different comparison type, use the
visdiff function and specify the
argument. You also can select from the available comparison types in the Comparison
Tool. For more information, see Compare Files and Folders and Merge Files.
As an alternative to the
visdiff function, use the Comparison
Tool to compare files or folders interactively. To open the Comparison Tool, go to the
Home tab, and in the File section, click
Compare. Then select the files or folders to compare.
You can also compare a file that is open in the Editor. On the Editor or Live Editor tab, in the File section, select Compare.
To compare a file with the autosave version or the saved version on disk, go to the Editor tab and click Compare and select Compare with Version on Disk or Save and Compare with Autosave. If your file is modified, the Editor saves the file before comparing. The Compare with Version on Disk and Save and Compare with Autosave 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 Preferences. Then, select Editor/Debugger and clear Save changes upon clicking away from a file.
To compare a file or folder in the Current Folder browser, right-click the selected file or folder and select Compare Against. To compare two files or subfolders, right-click the selected files or folders and select Compare Selected Files/Folders.