MD5 hash of .mat files varies

7 vues (au cours des 30 derniers jours)
HpW
HpW le 15 Fév 2022
Commenté : HpW le 16 Fév 2022
Hello.
I have some simiarly named.mat files, some of which are copies of each other, and I wanted to compare their MD5 hashes to find which ones contained the same data
None of the MD5 hashes matched, which doesnt make any sense because I know for a fact that some of them have the same data, but with different file names
I then ran an experiment where i saved the same .mat file multiple times,
save('N1.mat','variable')
save('N2.mat','variable')
save('N3.mat','variable')
N1, N2 and N3 all should be the same file, but they all have different MD5 hashes
Is this because of compression when the .mat file is saved? Is there any way to get around this?
tx!

Réponse acceptée

Stephen23
Stephen23 le 16 Fév 2022
Modifié(e) : Stephen23 le 16 Fév 2022
"Is this because of compression when the .mat file is saved?"
No, it is beacuse the .mat file includes the date and time when it was created/modified:
You can also see this very simply by opening a (non-compressed) .mat file in a text editor.
"Is there any way to get around this?"
No.
You could in theory remove the preamble part of the .mat file and hash the rest, but
  • that is not a trival task,
  • you would have to take into account different .mat file versions,
  • it does not work with the recent compressed .mat file versions.
The MATLAB documentation shows this interactive approach, which does not help you much:
The simplest code-based approach with the least effort is probably this:
A = load(matfile1);
B = load(matfile2);
isequal(A,B)
  1 commentaire
HpW
HpW le 16 Fév 2022
thank you for this explanation!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by