MD5 hash of .mat files varies

조회 수: 7 (최근 30일)
HpW
HpW 2022년 2월 15일
댓글: HpW 2022년 2월 16일
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!

채택된 답변

Stephen23
Stephen23 2022년 2월 16일
편집: Stephen23 2022년 2월 16일
"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
HpW
HpW 2022년 2월 16일
thank you for this explanation!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by