MATLAB: .mat files with the same data are different

binaryMATLAB

I'd like to diff two .mat files via the command line. However, it appears that the .mat files contains somewhat different data, even if (I think) they ought to be the same.
E.g.:
>> a = 3
a =
3
>> save('/<location>/filename.mat', 'a')
>> clear
>> a = 3
a =
3
>> save('/<location>/filename2.mat', 'a')
From the command line:
[matquest@computer <location>]$ diff filename.mat filename2.mat
Binary files filename.mat and filename2.mat differ
However, I can load the files and compare using isequaln and it returns true.
What is causing this difference? And is there a way to save the .mat files so that I can compare them using diff?

Best Answer

.mat files include a timestamp, so the binary files will clearly be different if they were created even just one millisecond apart. A naive binary comparison is therefore useless.
Read more about the file format here: