| Contents | Index |
visdiff('fname1', 'fname2')
visdiff('filename1',
'filename2', 'type')
visdiff('fname1', 'fname2') opens the Comparison Tool and presents the differences between the two files or folders. Either ensure that the two files or folders appear on the MATLAB path, or provide the full path for each file or folder. You can compare files or any combination of folders, zip files, or Simulink manifests.
If you have Simulink Report Generator™ software, you can select a pair of Simulink models (.mdl files) to compare XML text files generated from them.
visdiff('filename1', 'filename2', 'type') opens the Comparison Tool and presents the differences between the two files using the specified comparison type. type can be 'text' or 'binary'. If you do not specify type, visdiff creates the default comparison type for your selected files. The type option does not apply when comparing folders.
If there are multiple comparison types available for your selections (e.g., text, binary, file list, or XML comparison), you can create a new comparison and choose a different comparison type.
In the Comparison Tool, click the New comparison button.
The dialog box Select Files or Folders for Comparison opens and shows your previous comparison selections in the drop-down lists.
Change the comparison type and click Compare.
The visdiff function accepts fully qualified file names, relative file names, or names of files on the MATLAB path.
If the files you want to compare appear on the MATLAB path or in the current folder, you can specify the file names without the full path, for example:
visdiff('lengthofline.m','lengthofline2.m')or
visdiff('lengthofline','lengthofline2')If the files you want to compare are not on the path, either specify the full path to each file, or add the folders to the path.
For example, to specify the fully qualified file names to compare two example files:
visdiff(fullfile(matlabroot,'toolbox','matlab','demos','gatlin.mat'), ... fullfile(matlabroot,'toolbox','matlab','demos','gatlin2.mat'))
Specify the full path to files as follows:
visdiff('C:\Work\comp\lengthofline.m', 'C:\Work\comp\lengthofline2.m')You can specify paths to files relative to the current folder. For the preceding example, if the current folder is Work, then the relative paths are:
visdiff('comp\lengthofline.m', 'comp\lengthofline2.m')To view a comparison of the two example files, lengthofline.m and lengthofline2.m:
visdiff(fullfile(matlabroot,'help','techdoc','matlab_env',... 'examples','lengthofline.m'), fullfile(matlabroot,'help',... 'techdoc','matlab_env','examples','lengthofline2.m'))
For information about using the report features, see Comparing Text Files.
Note If the text files you compare are XML files, you see different results if you have MATLAB Report Generator installed. For details, see Comparing Files and Folders. |
To compare two example files:
visdiff(fullfile(matlabroot,'toolbox','matlab','demos','gatlin.mat'), ... fullfile(matlabroot,'toolbox','matlab','demos','gatlin2.mat'))
For information about the report features, see Comparing MAT-Files.
The following example code adds a folder containing two MEX-files to the MATLAB path, and then compares the files:
addpath([matlabroot '\extern\examples\shrlib'])
visdiff('shrlibsample.mexw32', 'yprime.mexw32')The Comparison Tool opens and indicates that the files are different, but does not provide details about the differences.
For more information on binary comparisons, see Comparing Binary Files.
You can perform file list comparisons for any combinations of folders and zip files. To view an example folder comparison and instructions for using the report features, see Comparing Folders and Zip Files.
To compare two example text files and specify comparison type as binary:
visdiff(fullfile(matlabroot,'help','techdoc','matlab_env',... 'examples','lengthofline.m'), fullfile(matlabroot,'help',... 'techdoc','matlab_env','examples','lengthofline2.m'), 'binary')
If you do not specify type, visdiff creates the default comparison type for your selected files, in this case, text comparison. By changing to the binary comparison type you could examine differences such as end-of-line characters.
Similarly, when you compare XML files without specifying type, you get a hierarchical XML comparison report. If instead you want a text or binary comparison, you can specify "text" or "binary" comparison types to see more details. When you compare zip files, the default comparison type is a file list comparison, and you might want to specify a binary comparison instead.
As an alternative to the visdiff function, compare files and folders using any of these GUI methods:
From the Current Folder browser:
Select a file or folder. Right-click the file or folder, and select Compare Against.
For two files or subfolders in the same folder, select the files or folders. Then, right-click, and select Compare Selected Files/Folders.
From the MATLAB desktop, select Desktop > Comparison Tool, and then select the files or folders to compare.
If you have a file open in the Editor, select Tools > Compare Against. You can use the Editor options browse, Autosave Version, or Compare Against Version on Disk.

Explore how to use MATLAB to make advancements in engineering and science.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |