visdiff - Compare two files or folders - MATLAB (original) (raw)

Compare two files or folders

Syntax

Description

visdiff([filename](#d126e1971502)1,[filename](#d126e1971502)2) opens the Comparison Tool and displays the differences between the two files or folders. The Comparison Tool supports MATLAB® code files, zip files, MAT files, and various other MATLAB and Simulink® file formats. For a complete list, see Input Arguments.

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

example

visdiff([filename](#d126e1971502)1,[filename](#d126e1971502)2,[type](#d126e1971746)) compares two files using the specified comparison type. If you do not specify a type, visdiff uses the default comparison type for your selected files. You can use this syntax to compare files only.

example

[comparison](#d126e1971800) = visdiff(___) compares two files and returns a comparison object that contains the differences between the specified files. Use the comparison object to manipulate the comparison at the command line, for example by applying filters and publishing comparison reports. This syntax does not open the Comparison Tool and does not require a display. It is particularly useful for automating the creation of comparison reports for continuous integration (CI) workflows. This syntax does not support all file types. Supported files include Simulink models, plain text files, MATLAB scripts, MATLAB apps, and text-based source code files.

example

Examples

collapse all

Compare Two Files

This example shows how to compare two files using 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 MAT files gatlin.mat and gatlin2.mat using a fully qualified file name.

visdiff(fullfile(pwd,"supportingFiles","mymatFiles","gatlin.mat"), ... fullfile(pwd,"supportingFiles","mymatFiles","gatlin2.mat"))

Compare Two Files and Specify Type

Compare the two files lengthofline.m and lengthofline2.m as binary.

If you do not specify the comparison 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")

Programmatically Publish Comparison Report

When you compare Simulink models, you can manipulate the comparison report at the command line by specifying an output argument.

Compare two model files and return a comparison object.

comparison = visdiff(modelname1,modelname2);

You can disable all filters from the model comparison report.

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)

Create a PDF comparison report named myreport. Save the report to the comparisonresults folder.

file = publish(comparison,format="PDF",Name="myreport",OutputFolder="comparisonresults"); web(file)

Supported report formats are HTML, PDF, and DOCX.

For instructions on how you can use visdiff to generate reports in your continuous integration workflows, see Attach Model Comparison Report to GitHub Pull Requests (Simulink).

Input Arguments

collapse all

filename — File or folder name

character vector | string

File or folder name, specified as a character vector or string.filename can include a relative path to the current folder or a full path.

This table shows the supported file types.

File Type File Extension
MATLAB
MATLAB script .m
Live script .mlx
Plain text Any
Text-based source code .c, .cpp,.java, etc.
MATLAB App .mlapp
Binary Any
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
Other products
Requirements Toolbox™ .slreqx. For more information, seeCreate and Save Printable Reports of Comparison Results (Requirements Toolbox)
Requirements Toolbox links .slmx. For more information, see Create and Save Printable Reports of Comparison Results (Requirements Toolbox)
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.

type — Comparison type

"text" | "binary" | "xml"

Comparison type, specified as "text","binary", or "xml". Some comparisons do not support all of the comparison types. If you specify a comparison type that is not supported, MATLAB displays an error.

To examine differences such as end-of-line characters in text files, specify the "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 — Comparison object

object

Comparison object for manipulating the comparison at the command line, for example, by applying filters and publishing comparison reports. Supported files include Simulink models, plain text files, MATLAB scripts, MATLAB apps, and text-based source code files.

Limitations

Alternative Functionality

You can open the Comparison Tool interactively.

Version History

Introduced in R2008b

expand all

R2023b: Publish comparison reports for MATLAB apps

Starting in R2023b, you can return a comparison object when you compare MATLAB apps. Use the comparison object to publish comparison reports programmatically.

R2023a: Publish comparison reports for plain text, MATLAB scripts, and text-based source code

Starting in R2023a, you can return a comparison object when you compare plain text files, MATLAB scripts, and text-based source code files. Use the comparison object to publish comparison reports programmatically.

R2023a: XML comparison type will be removed in a future release

XML comparison type will be removed in a future release. Overriding the default comparison type by specifying "xml" will not be possible in a future release. In R2023a, scripts that usevisdiff(filename1,filename2,"xml") continue to work.

See Also

Topics