Convert MAT file to v7.3
63 views (last 30 days)
Show older comments
I have 2 questions:
1) The latest version of the MAT file is v7.3. Are all older MAT file versions able to be converted to a v7.3 file losslessly? i.e. does v7.3 support all datatypes/metadata supported by previous file formats?
2) What is the best way to convert old MAT file formats to v7.3 MAT files?
It seems like the following code snippet works pretty well for converting old MAT file formats to v7.3:
clear;
load('OldVersion.mat');
save('NewVersion.mat','-v7.3','-nocompression');
Is there any situation where this code snippet would fail for some reason?
Thanks everyone. If you want context for these questions, I've been asked to ingest MAT files into a data pipeline. The MAT files that I'm getting are v4 - v7.3. I've discovered that the latest v7.3 MAT files are HDF5 compliant files. Rather than adjust our (non-MATLAB) data pipeline to be able to handle all MAT file versions, it seems easier to upgrade incoming MAT files to v7.3 and just to use our well supported/documented HDF5 library for ingestion.
3 Comments
Stephen23
on 17 Sep 2021
You can load and save the individual (or any selected) variables using the structure approach too.
Answers (1)
Stephen23
on 17 Sep 2021
Edited: Stephen23
on 17 Sep 2021
You can load and save the individual (or any selected) variables using the structure approach too. Lets try it:
A = 1:3;
B = 4:6;
C = 7:9;
save('old.mat','A','B','C','-v4')
clearvars
W = whos('-file','old.mat');
W.name
S = load('old.mat',W(1).name);
save('new.mat','-struct','S','-v7.3','-nocompression')
for k = 2:numel(W)
S = load('old.mat',W(k).name);
save('new.mat','-struct','S','-append','-nocompression')
end
Checking:
type new.mat
whos('-file','new.mat').name
0 Comments
See Also
Categories
Find more on HDF5 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!