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.
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 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 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.
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
'html' (default) – single-file
HTML Document, or
'docx' – Microsoft® Word 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
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
File or folder name to compare, specified as a character vector.
name can include a relative path, but the relative
path must be in the current folder. Otherwise,
include a full path.
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 some cases, there might be multiple comparison types available for your selection
(e.g., text, binary, file list, or XML comparison). To select a different comparison
type, use the
visdiff function and specify the
type argument. You also can select from the available
comparison types in the Comparison Tool. For more information, see Compare Files and Folders.
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
with the autosave version or the version on disk, select Compare
, and then select
Save and Compare with
Compare with Version on Disk.
For more information, see Compare Files with Autosave Version or Version on Disk.
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.