MD5 hash of .mat files varies

8 Ansichten (letzte 30 Tage)
HpW
HpW am 15 Feb. 2022
Kommentiert: HpW am 16 Feb. 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!

Akzeptierte Antwort

Stephen23
Stephen23 am 16 Feb. 2022
Bearbeitet: Stephen23 am 16 Feb. 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 Kommentar
HpW
HpW am 16 Feb. 2022
thank you for this explanation!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by