• “Select Text Files to Compare” on page 6-11
• “Highlighting of Differences” on page 6-12
• “Step Through Differences” on page 6-14
• “Merge Differences” on page 6-14
• “View a Summary of Differences” on page 6-15
• “Ignore White-Space Differences in Text Comparisons” on page 6-16
• “Show Differences Only” on page 6-16
• “Change the Display Width of a Text Comparison” on page 6-16
• “Save HTML Report” on page 6-16 Select Text Files to Compare
To select files to compare, see “Select the Files or Folders to Compare” on page 6-6.
To view an example text comparison, enter:
visdiff(fullfile(matlabroot,'help','techdoc','matlab_env',...
'examples','lengthofline.m'), fullfile(matlabroot,'help',...
'techdoc','matlab_env','examples','lengthofline2.m')) Highlighting of Differences
When you use the Comparison tool to compare two text files, a window opens and
presents the two files side by side. Symbols indicate how you can adjust the files to make them match. This feature can be useful when you want to compare the latest version of a text file to an autosave version.
The Comparison tool report displays the files side by side and highlights lines that do not match, as follows:
• Dark pink highlighting indicates changed characters within lines.
• Pink highlighting and an x between the two files indicate that the content of the lines differs between the two files.
• Green highlighting and a right (>) or left (< ) angle bracket between the two files indicate a line that exists on one side only.
Comparing Files and Folders
The Comparison tool attempts to match lines and detects local text that is added, deleted, or changed. It does not do a simple line-by-line comparison. In the previous image, for example, the tool determines that lengthofline.m has a line of code that does not exist in lengthofline2.m and highlights it (line 24) in green. Also, notice that the tool
takes the additional line into account and determines that the line containing the end statement in each file matches, even though the end statement does not occur on the same line number.
If the files you are comparing are extremely long, the tool could run out of memory while attempting to perform the file comparison. In which case, the message,
Maximum file length exceeded.
Defaulting to line-by-line comparison.
appears. In a line-by-line comparison, the tool highlights the lines containing the end statement because in performing this operation, it finds that the last line in one file does not match the last line in the other file.
Step Through Differences
Because text files can be lengthy, the Comparison tool provides toolstrip buttons to help you step through the results from one difference to the next.
To navigate through comparison results:
• Click the right arrow button to go to the next set of lines that differ.
If no additional sets of lines differ, the right arrow takes you to the end of the file.
• Click the left arrow button to go to a previous set of lines that differ.
If no previous set of lines differ, the left arrow takes you to the beginning of the file.
Merge Differences
When comparing text files you can merge changes from one file to the other. Merging changes can be useful when resolving conflicts between different versions of files.
Tip You can only merge from left to right. If you want to merge into the other file, use Swap Sides before you start merging. Swap Sides reverts any merges already made
Comparing Files and Folders
Merged differences display gray row highlighting, and a green merge arrow.
The merged file name at the top of the report displays the dirty flag (filename.m*) to show you that the file contains unsaved changes.
2 To revert the last merge operation, click Undo in the Merge section. You can click Undo repeatedly, or Redo to reapply a merge.
Tip You can click Swap Sides to start again and revert all merges.
3 To save your changes, click Save Merged File. To save to a different name, select Save Merged File+Save Merged File As.
4 If you want to inspect the files in the Editor, click the line number links in the report.
Tip Save your merge changes from the comparison report before making any changes in the Editor, otherwise the comparison report can become incorrect. The report does not update to reflect changes you make in the Editor.
View a Summary of Differences
To see a summary of differences between two text files, scroll to the bottom of the Comparison tool and view the list, which contains information such as:
• Number of matching lines: 51
• Number of unmatched lines in left-hand file: 13
• Number of unmatched lines in right-hand file: 16
Ignore White-Space Differences in Text Comparisons
You may want to hide white-space differences to help you distinguish between functional changes and changes to indentation.
On the View tab, click the Filter button, and check or uncheck the Ignore White Space item to toggle the display of differences only involving white-space characters.
Show Differences Only
You can specify whether to show only differences or entire files. It can be useful to hide unmodified lines in large text comparison reports. When you are showing differences only and sections are hidden, the report displays messages like the following: 10 unmodified lines hidden.
On the View tab, click the Filter button, and check or uncheck the Show Differences Only item to toggle the display of sections of the report that do not contain any
differences.
Change the Display Width of a Text Comparison
You can increase or decrease the line lengths of the text files in the comparison display.
On the View tab, in the Display section, edit the number in the Column Width edit box. Resize the window, if necessary.
For details on other comparison tool features, see “Using Comparison Tool Features” on page 6-21.
Save HTML Report
On the Comparison tab, in the Comparison section, click Save As > Save as HTML to save a copy of the comparison report as an HTML file.