appending variables in save causing file corruption
12 次查看(过去 30 天)
显示 更早的评论
Hi,
I have some .mat files containing several variables of type 'Table'. I perform some analysis and replace some of these variables using the command
save('FileName', {'VarX', 'VarY', etc}, 'mat', '-append')
In this case there are other variables in the file appart from VarX and VarY which I am not overwriting. this seems to work most of the time, but every now and again i get an error:
Error using save
Error closing file 'FileName'
The file may be corrupt.
The files I am dealing with are around 250-500MB in size.
Any ideas why this might happen? It means I then corrupt my original data which is annoying. Perhaps I am best to create a totally new file with the new data and then replace the old file, therefore if I do get a corrupt file when writing I won't have destroyed my original data.
Thanks
Oli.
2 个评论
Robert Reid
2021-4-17
编辑:Robert Reid
2021-4-17
Hi Oli,
I think that I am running into the exact same problem - your description at least matches my issue exactly.
Did you ever find a good solution to this?
Just saw Sai's answer below - did matfile help solve this issue?
Thanks,
Rob
回答(1 个)
Sai Bhargav Avula
2019-11-6
编辑:Sai Bhargav Avula
2019-11-6
Hi,
One reason that the files get corrupted is because you might be trying to overwrite it before it could save the old process.
Also I would recommend you to use the matfile, as it can access and change the variables without loading it into the memory. Because of this the MAT file object requires less memory than the load and save commands.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!