MATLAB: Does the FIG file increase in size when I open and re-save it

MATLAB

Why does my figure file increase in size when I open and re-save it? My figure file jumps from being ~100 KiB to ~4700 KiB just by opening and re-saving.
% example.m
fname = 'tst.fig';
print_file_size(fname);
fig = openfig(fname);
savefig(fig,'tst2.fig');
print_file_size('tst2.fig');
function print_file_size(fname)
s = dir(fname);
fprintf('%s: %.2f KiB\n',fname,s.bytes/1024);
end
————————————————————
>> example
tst.fig: 111.98 KiB
tst2.fig: 4724.23 KiB

Best Answer

  • FIG file size is affected by the default MAT-file format, which is set in the MATLAB preferences.
    On the Home tab, go to Preferences > General > MAT-Files and make sure that the selected MAT-file format is NOT 7.3. The version 7.3 format has been known to increase the file size for complicated structures.
    You should now notice that opening and re-saving the FIG file increases the file size very little (if at all).
    e.g. Using MAT-file version 7 with the above script gives me the following.
    >> example3
    tst.fig: 111.98 KiB
    tst2.fig: 112.56 KiB