isequal vs. visdiff for .mat files?

19 visualizaciones (últimos 30 días)
John R.
John R. el 19 de Ag. de 2015
Comentada: Walter Roberson el 19 de Ag. de 2015
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 comentario
John R.
John R. el 19 de Ag. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de Ag. de 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 comentarios
John R.
John R. el 19 de Ag. de 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 el 19 de Ag. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by