save with "'-append" on table increase file size without modification of the variable
Show older comments
I create a table of 100x100, then save it:
t = array2table(rand(100));
save('table.mat', 't')
The file weight 76 Ko. Then, without changing t, I re-save it with append:
save('table.mat', 't', '-append')
The file now weight 152Ko (76*2), and it will add 76Ko each time I append the same table.
If you load the table, it's the same than the original one:
s = load('table.mat', 't');
setdiff(s.t, t) % It's empty
The documentation do say "save(filename,variables,"-append") adds new variables to an existing file. If a variable already exists in a MAT-file, then save overwrites it with the value in the workspace.", but the size of the MAT-File increase by the size of the table each time.
What is happening with the -append option ?
4 Comments
dpb
on 30 Aug 2024
I can confirm a similar behavior w/ R2021b; it appears as though the '-append' option for a table (perhaps any compound class?) adds some overhead to the .mat file. Whether this is a bug or a feature, I think only a bug/support request to Mathworks will be able to answer.
The -append option does not remove or rearrange any existing data from the mat file. The reason is simply that rearranging/overwriting existing data would take time: potentially much more time than it takes to write your new data.
It is not a bug and is the same for all MATLAB versions.
A search of this forum will bring up several existing threads that discuss this in detail.
Walter Roberson
on 30 Aug 2024
save -append works by first appending the new data to the .mat file, and then going back through the .mat file and marking previous versions of the variable as being unused.
Arthur Roué
on 3 Sep 2024
Accepted Answer
More Answers (0)
Categories
Find more on Workspace Variables and MAT Files 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!