.mat files with the same data are different
5 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Stephen23
2018-1-29
编辑:Stephen23
2018-1-29
.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:
4 个评论
Steven Lord
2018-1-30
You could configure your source control system to use the differencing and merging tools provided by MathWorks for our file formats.
更多回答(1 个)
Walter Roberson
2018-1-29
There is no way to save the .mat files so that you can compare them using binary diff.
.mat files include information about the time of creation.
Remember too that different .mat files might have the same data in a different order.
Also, when a .mat file is updated using save with the -append flag, then "holes" can be left in the .mat file -- when the new version of a variable is larger than the old version with the same variable name, and it is not the last variable in the file, then MATLAB marks the old space as unused and writes the new version at the end of the file (or perhaps at the first place in the .mat file where it finds enough available space.) Therefore .mat files that load the same data might not have the same size (because one might have holes) or same order.
If object-oriented objects are saved, then in some cases two objects might look the same but have different serialization. Information about serialization in MATLAB is not easy to find, but at least in some programming systems, serialization can involve keeping "generation number" (incremented on every write to the object, or sometimes to the structure of the object) to allow easy determination of who has the newer version of the content.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!