isequal vs. visdiff for .mat files?

19 次查看(过去 30 天)
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 个评论
John R.
John R. 2015-8-19
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2015-8-19
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 个评论
John R.
John R. 2015-8-19
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 2015-8-19
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

尚未输入任何标签。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by