Why does my .mat file keep getting corrupted?? 😖

At the beginning of my script I load my workspace variables..
load SA_Measurements
At the end of my script I save.
save("SA_Measurements.mat",'Main_Settings','Main_TF','Sub_Settings','Sub_TF','Results','-append');
I can run the script on the same day without problems. If I come back a month later, I get an error about the file being corrupt and it won't load at all or, like today, it will load some of the variables and show this error: Error using load
Cannot read file /Documents/MATLAB/SubAligner/SA_Measurements.mat.
I've been through many forum posts, but can't find a solution. What am I doing wrong??

5 comentarios

dpb
dpb el 24 de Nov. de 2020
Certainly nothing looks wrong programmatically -- one wonders a couple things:
  1. The use of '-append' adds to a previous .mat file which always gives a chance for something to happen. Can you create a system of rotating backup files that are each complete instead, perchance?
  2. Have you upgraded versions between? .mat file format is not supposed to change but there's always that outside chance something happened, although anything systematic would be found and flagged by a multitude of users very quickly.
If this happens repeatedly, it's probably worth opening a support ticket contacting TMW Support.
Nathan Lively
Nathan Lively el 25 de Nov. de 2020
Thanks for the feedback dpb.
> Can you create a system of rotating backup files that are each complete instead, perchance?
Yes, good idea. Also, there's no reason for me to use -append. I'm actually just saving the same variables every time.
> Have you upgraded versions between?
No, but I was planning to upgrade tomorrow to see if that would help the situation.
> If this happens repeatedly,
It has! I will. :)
Robert Reid
Robert Reid el 17 de Abr. de 2021
Nathan,
Did you find a solution to this?
I ask because I have been having a similar issue using -append when saving. Once in a while the data file will get corrupted during the saving process. I'll notice as matlab locks up, at least temporarily, when this happens.
Jan
Jan el 17 de Abr. de 2021
@Robert Reid: Please post any details, preferrably in a new thread.
Hey Robert. Maybe? I have made some changes and have only had the issue once since making the changes.
  1. I changed load SA_Measurements to load('SA_Measurements.mat'). I really don't think that did anything, but I noticed it when I looked up the doc for load.
  2. I changed
save("SA_Measurements.mat",'Main_Settings','Main_TF','Sub_Settings','Sub_TF','Results','-append');
to
save('SA_Measurements.mat','Main_Settings','Main_TF','Sub_Settings','Sub_TF','Results');
The main thing is that I got rid of the -append. I still use it occasionally, but try to avoid it.
I also immediately save a backup of that MAT file on the next line. I have only had to use it once, but was glad it was available.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Performance and Memory en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 24 de Nov. de 2020

Comentada:

el 20 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by