isequal vs. visdiff for .mat files?

8 views (last 30 days)
Hello,
I'm trying to compare two mat files to see if there are any differences between them. These mat files contain inputs and outputs of a trajectory model I've created, and are comprised of structures, strings, doubles, cells, etc.
When I use isequal, it returns a '0' indicating they are not equal. But when I use visdiff to compare them it does not find any differences.
visdiff says " The variables in these files are identical, but the files are not. The differences may be caused by file formats, file timestamps, or the order in which the variables are stored."
The variables are in the same order. What is the timestamp? Can it be ignored?
Thank you.
  1 Comment
John R.
John R. on 19 Aug 2015
Also, the mat files can contain NaN values, but if I use isequaln it will still give me a '0' even though they are identical.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 19 Aug 2015
Timestamps can be ignored. If you were to save the same data twice, it would record the time of each save and so the files would not be identical.
However, how are you using isequal() on the .mat files? Are you load()'ing the content and using isequal() on the structures, or are you using isequal() on the file names ?
  2 Comments
John R.
John R. on 19 Aug 2015
I'm using isequal on the file names, e.g...
isequal('file1.mat', 'file2.mat')
But after further testing, it would appear that using isequal on the file names is simply comparing the actual files names, not what's in them. I compared mat files that didn't even exist and it did not give me an error; it's just comparing the strings at that point.
I suppose if I want to use isequal I will need to compare each item in the mat files.
My goal is to first identify if the mat files are different, and if they are then open visdiff.
Walter Roberson
Walter Roberson on 19 Aug 2015
First dir() the two files and compare their sizes. If the sizes differ then the files must be different (but the difference might not be important)
After that you could hash each of the files and compare the hash http://www.mathworks.com/matlabcentral/fileexchange/31272-datahash
Or you could fileread() each of the files and isequal() the result, if you have enough memory.
The advantage of using fileread() is that you could zero the bytes that are used for the timestamp, against the possibility that the same data was saved twice exactly the same way.
You can also use whos with the -file option and isequal() the structures that result, to determine whether there is a difference in the names of variables or their sizes or class. A step beyond that would be to sort that by variable name, if you want to deal with the possibility that the same data was stored but with a difference in the order of the variables.
Identical whos does not promise that the files are identical.

Sign in to comment.

More Answers (0)

Categories

Find more on Variables in Help Center and File Exchange

Tags

No tags entered yet.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!