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 Center および File ExchangeGet 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