Save -append increases mat file size

9 ビュー (過去 30 日間)
Azucena Mendoza
Azucena Mendoza 2022 年 2 月 16 日
編集済み: Pritesh Parmar 2025 年 4 月 17 日
Hi, I have a mat file that is being updated with the function save('myfile.mat', 'myvar' -append). Everytime this function is called, my mat file increases a lot in size, even though the 'myvar' has not changed. Does anybody know how I can fix this?
  6 件のコメント
Azucena Mendoza
Azucena Mendoza 2022 年 2 月 18 日
I am using version 7, compression.
I was thinking, I could first load the entire MAT file and then update only the variable I need to change and in the end save all variables without -append.
However, that doesn't seems to be the most efficient and elegant solution.
Walter Roberson
Walter Roberson 2022 年 2 月 19 日
When you -append to a -v7 or earlier .mat file, it doesn't update anything existing in the file: it just adds on the blob that represents the new variable. Part of the semantics of those files is that any program reading from them is responsible for scanning the content of the file, and finding the last blob with the desired variable name and using that. Earlier blobs with the same name are not even marked as deleted or as something that can potentially be released.
It is the presentation_final_final_final_last_final.doc kind of storage: you don't stop looking in your folder when you see presentation.doc or presentation_final.doc, you keep looking for the newest version and use that, leaving all the other ones where they are. Any cleanup comes later.

サインインしてコメントする。

回答 (1 件)

Pritesh Parmar
Pritesh Parmar 2025 年 4 月 15 日
編集済み: Pritesh Parmar 2025 年 4 月 17 日
As a workaround, you could try loading the variables you want to preserve and save the MAT file again with both the variables you want to preserve and updated variables. Try the following code: fastSaveUpdate - Efficiently update variables in MAT-file - File Exchange - MATLAB Central
Pritesh Parmar

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by