Main Content

visdiff

Compare two files or folders

Description

example

visdiff(name1,name2) 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.

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

example

visdiff(name1,name2,type) compares the two files or folders using the specified comparison type. If you do not specify a type, visdiff uses the default comparison type for your selected files. The type option does not apply when comparing folders.

example

comparison=visdiff(___) 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. name1 and name2 must be model files. Use the comparison object to manipulate the comparison at the command line, for example by applying filters and publishing comparison reports.

Examples

collapse all

Compare two files using both 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 demo files gatlin.mat and 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 lengthofline.m and 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.

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

When comparing Simulink models, you can manipulate the comparison at the command line by specifying an output argument to visdiff.

Compare two model files and get the comparison object output from visdiff.

comparison = visdiff(modelname1,modelname2);

(Optional) Filter the comparison result. Supported filters are: 'unfiltered' – removes all filtering from the comparison, or 'default' – default filtering strategy for comparisons.

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)

To specify options for the report, use the following name-value pairs with publish.

  • 'Format' – The file format of the published report.

    Options are: '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 'Format' is ignored.

  • '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 options structure: publish(comparison, options).

Input Arguments

collapse all

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, name must include a full path.

The following table summarizes the list of supported files.

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
Dependency SMF.smf
Other products
Requirements Toolbox™.slreqx
Requirements Toolbox links.slmx
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 an unsupported comparison type is specified, MATLAB displays an error.

To examine differences such as end-of-line characters in text files, specify a '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. Only supported for comparing Simulink models.

Limitations

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.

Tips

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 type 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.

Alternative Functionality

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.

Version History

Introduced in R2008b