How to reduce the file size of MAT files?
Show older comments
My MAT file is around 7 GB. It has been very slow to read and write into this file. I wonder if there are ways I can make the file smaller?
Will it help to round the values to just two digits after the decimal point?
Accepted Answer
More Answers (1)
the cyclist
on 4 Jun 2025
0 votes
It's not really as simple as "rounding", as the memory requirements are dependent on the data type. But, there are different numeric data types in MATLAB, and some take less memory than others.
By default MATLAB stores numbers in double-precision. If you don't need that much precision, then you can calculate in single-precision. (That is kinda like rounding them to a smaller number of digits.)
You can also store as integers of various sizes, or as binary, but it sounds like you need at least some floating-point numbers.
3 Comments
Leon
on 5 Jun 2025
It would be helpful if you could give us more details about the contents of your struct. For instance, if you have numbers stored in the struct as text (strings), then you are almost certainly better off converting these to actual numeric values using e.g. str2double . As others have said, maybe you can get away with calling single to half the storage for those fields. Another similar case might be if you have text data that consists of a few different fixed strings - in that case, you could use categorical, maybe like this:
s.myField = {'string1', 'string2', 'string1', 'string2', 'string3', 'string1', ...
'string2', 'string3', 'string2', 'string3', 'string1', 'string2'};
whos
s.myField = categorical(s.myField); % convert from text to categorical
whos
Even in this trivial case, you can see the categorical type uses much less space.
Leon
on 5 Jun 2025
Categories
Find more on Logical 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!