This week I’d like to welcome back guest poster, Malcolm Wood, to describe the enhancements to the File and Folder Comparison tool.
Over the last few releases we have made some major enhancements to the Comparison Tool in MATLAB, giving you more flexibility over what you can compare, more detail about the differences, and in some cases the ability to merge changes from one file to another.
In previous releases you could compare folders with other folders, ZIP-files with other ZIP-files, and Simulink manifest files with other Simulink manifest files. But since R2010b you can compare any of these with any other, treating each as a container for a list of files. So if you created a back-up of your work in a ZIP-file one day, you can use the Comparison Tool to examine the differences between the back-up and the folder containing your current work:
In R2011a we implemented some improvements to the MAT-file comparison report. It now shows the data types and sizes of your variables, and there’s the option to “merge” the differences between the files (1), i.e. to copy a variable from one file to the other. Be careful with this, because there’s no easily accessible “undo” feature for MAT-file merge. Instead, a back-up file is created to help you in case you make a mistake, and the report includes instructions on how to recover the previous values (2).
The other major new capability here is the option to compare the contents of the variables. Clicking the little magnifying glass icon (3) opens the “Variable Comparison” window. There are several different views, depending on the data type. Here is how it looks for a structure:
And by double clicking on a field in the structure you can compare the values inside. This is how it looks for the “hand2” field, which is a numeric array:
We have also introduced some features to make it easier to concentrate on the important changes between text files. In R2010b we made it possible to ignore differences that involve only the number of “whitespace characters” in a line or between lines (4). So if all you did was change the indentation in your MATLAB code, these won’t show up as differences, leaving you to focus on changes which actually matter to your results. And in R2011a we made it possible to hide sections of the file which contain no changes (5), saving you a lot of scrolling if you are looking at only a few changes among thousands of lines of text.
Those of you who work on both Windows machines and Linux or Unix machines may be familiar with the problem of trying to compare files which use different types of end-of-line character. Some differencing tools will show every line as different, making it impossible to see where the actual text has changed. Others will ignore the end-of-line characters, perhaps leaving you scratching your head as to why two files of different sizes are reported as being identical by your differencing tool.
In R2011b we have two features to help you. Firstly, when comparing files as text and finding no differences to display, MATLAB will also check the sizes of the files and include the result in the report (6).
Secondly, we enhanced the “Binary Comparison” report so that it can show the individual bytes that are different. By clicking the “New Comparison” button (7) and choosing “Binary Comparison” in the dialog you can generate a report like this one which enables you to see the additional carriage-return bytes (8):