How do I recover data from a corrupt MAT-file?

146 views (last 30 days)
When I attempt to load a MAT-file created in MATLAB 7.2 (R2006a), I receive the following error:
???Error using ==> load
Unable to read MAT file /home/$dir
File may be corrupt.
I, however, am able to view the variables in the MAT-file with the following command:
whos -file corruptMATFileName
I would like to recover this data. The MATZEROFIX file I found on MATLAB Central did not recover the data.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 3 Jun 2019
Edited: MathWorks Support Team on 3 Jun 2019
The issue might be caused by the presence of a corrupt zero-byte tag in the MAT-file. If this is the case, one might be able to extract the data from the MAT-file until a corrupt zero-byte tag is reached.
Please download the following SPLITMAT file in your current folder of MATLAB. Also, please ensure that the corruptMATFile is in the same current folder.
Then use the command as detailed below:
splitmat corruptMATFileName % Do not include the .mat extension
The above command will generate "n" MAT-files: corruptMATFileName_1.mat through corruptMATFileName_n.mat, each containing a variable contained in the original MAT-file.
If this command does not work, you may also try the following syntax to recover non-corrupted variables from the MAT-file:
>> load('<corrupted_file>.mat', '<uncorrupted_variable>');
Stelios Fanourakis
Stelios Fanourakis on 6 Jul 2018
Thanks Walter. Problem solved as I found a backup of the fig.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!