Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

visdiff

Compare two files or folders

Syntax

visdiff(name1,name2)
visdiff(name1,name2,type)
comparison=visdiff(___)

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.

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 qualfied 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, 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 '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. name can include a relative path, but the relative path must be in the current folder. Otherwise, name must include a full path.

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.

Tips

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 Comparing Files and Folders.

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 with the autosave version or the version on disk, select Compare , and then select Save and Compare with Autosave or Compare with Version on Disk. For more information, see Comparing 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.

Introduced in R2008b

Was this topic helpful?