How to reduce the file size of MAT files?
이전 댓글 표시
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?
채택된 답변
추가 답변 (1개)
the cyclist
2025년 6월 4일
0 개 추천
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
Leon
2025년 6월 5일
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
2025년 6월 5일
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!