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)

更多回答(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