MATLAB: Visdiff Message: The Files are Equivalent but the Files are not Identical

MATLAB

I am trying to compare two MAT files and I get the following message in the report:
"The variables in these files are equivalent, but the files are not identical. Possible causes of the differences include: file formats, file timestamps, NaN patterns, field ordering, or the order in which the variables are stored."
This brings up two questions:
1) What are the "file formats" that show in the compare report? I was under the impression I was comparing two MAT files so why would this report say that they are not the same?
 
 2) What are the "NaN patterns" that show in the compare report?
 
 

Best Answer

1)
The way which data is saved to MAT-files has changed over the years. What this means is that the same data may be serialized to a file in different ways.
In the MAT-File comparison, a binary comparison is performed on the two files before loading them and comparing their contents. If the data has been serialized in a different way, the binary comparison would indicate a difference.
 
Users can choose which <http://www.mathworks.com/help/matlab/import_export/mat-file-versions.html MAT-File version> they want to use if they don’t want to use MATLAB’s default (which also changes across releases). This message could be caused by saving MAT-files in different MATLAB releases.
2)
You will have noticed that if you evaluate the expression:
 
0.0/0.0
 
In MATLAB, then you will see the result:
 
ans =
           NaN
 
If, however, you were to evaluate same expression in native code without any special signal handling, your program will most likely terminate with
 
*                *floating point exception (core dumped)
 
printed to the console.
 
The use of NaN following an illegal floating point computation is one example of a “NaN pattern”: MATLAB handles floating point exceptions and uses NaN patters to indicate an illegal value and allow a user to continue working.
 
For the sake of brevity, there are different types of NaNs, each of which have different usages/behaviour. You can read more about them in <https://en.wikipedia.org/wiki/IEEE_754 IEEE 754> .
In the context of comparisons, a NaN compared with itself or another is defined as false.
 
     NaN == NaN
     ans =
          logical
           0
 
More on NaN comparisons and different NaN patterns <https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN here>.