Matlab crashes randomly when saving mat-files.

I have Matlab version 2014a running on Windows 7. I have recently observed at several occasions the strange Matlab behaviour concerning the importing and saving mat-file binary format files. I will describe the issue in the pseudocode since the actual code is too long and specific to post here. The whole program is a for loop cycling through a series of many binary files (100-1000) of moderate size (~100 MB). I just read data from each file, do some processing on it and finally save the corresponding modified data. The problem is that Matlab crashes during this process. The error occurs very rarely and at complete random (for the same set of files). E.g., if I want to process 1000 files, Matlab may crash when processing the file #730 in the sequence. I discovered that the error is triggered exclusively during save command.
for k=1:N
extract data from a file #k
do some processing on the current data
save modified data
end
I have found on this forum that some people encountered similar difficulties but I still do not understand what is really happening.
I slightly modified the code above so that the program does not crash when it fails at some stage during saving the current modified data. Specifically, I nested infinite while loop inside for loop. The while loop is always terminated for each iteration of for loop after successful saving of the actual data. If saving of the current modified data fails, then I display a warning message saying that the error has occured, some information that helps me to identify the cause of the error as well as to save the current workspace. Some people reported that it sometimes helps to repeat saving of the data if it fails at the first attempt. That is why I repeatedly (3 times in this code) try to save the current data before I give it up and continue to the next iteration of for loop (file). Strangely enough, this more complicated code does not work either. If the save error occurs at any moment during the code execution, then repeated attempts to save the file fail as well and what is even worse the save error occurs for all subsequent files (corresponding to next iterations of for cycle).
max_num_repetitions = 3;
for k=1:N
error_counter = 0;
while true
extract data from a file #k
do some processing on the current data
try
save modified data
break % No error detected -> process to the file (iteration)
catch % saving fails
display the warning
display info about the current data (matrix dimensions, etc.)
try
save the current workspace
catch
warning('Saving of the workspace failed ')
end
if error_counter>= max_num_repetitions
break
end
end
end
end
I already experienced a lot of issues with storing data in mat-format before encountering this problem. This was especially the case if data was huge (500 MB -1500 MB) and/or had complicated organization including cell arrays, objects, nestes structures, etc. Specifically, it happened to me quite often that I was able to save data successfully but when I imported it back to Matlab, I got an error message: "File may be corrupt". It was sometimes possible (but not always) to recover data from a corrupt mat-file http://www.mathworks.com/matlabcentral/answers/98890-how-do-i-recover-data-from-a-corrupt-mat-file). The only parameter I can play with when saving data is the version of mat-file but changing the default version v7 to the version v7.3 did not help.The situation is now quite different as I am storing relatively small data (100 MB) that has a simple array structure. Yet, the save function works erratically. My question is how to handle this problem.

2 件のコメント

Jan Palacky
Jan Palacky 2015 年 11 月 5 日
This is rather strange but I start to believe that there is something wrong with the compression algorithms that comes with v7 and v7.3 mat-file formats. I don't know if I am just lucky but I have not experienced any program crash till now when I save data as an uncompressed v6 mat-file format. I never considered this format before but now to be on safe side I am forced to use this format. Furthermore, there is no significant redundancy in my data (just plain matrices) and thus compressed data are only about 10% smaller then uncompressed data. The compression is no advantage for me and comes at the expense of very high computational cost and reliability. Specifically on my laptop, v7 and v7.3 mat-files are saved roughly 10 and 20 times slower than the uncompressed format, respectively.
Image Analyst
Image Analyst 2015 年 11 月 5 日
Where are you incrementing error_counter?

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeWorkspace Variables and MAT Files についてさらに検索

質問済み:

2015 年 11 月 3 日

コメント済み:

2015 年 11 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by