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

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.

 Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 3 Juin 2019
Modifié(e) : MathWorks Support Team le 3 Juin 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>');

6 commentaires

Ingrid
Ingrid le 20 Jan 2014
thanks for posting this code, it worked great on my mat-file that I could not open anymore and I was able to recover the data that I needed. Recreating it would have taken a very long time so I am very happy that it worked although I do not know what caused the corruption of the file in the first place.
James Tursa
James Tursa le 20 Jan 2014
Modifié(e) : MathWorks Support Team le 15 Mai 2023
If the problem is caused by invalid variable or field names in the file, the following FEX submission might help as well:
I had no problem downloading the loadfixnames contribution by clicking on Download Zip.
Esha Bhargava
Esha Bhargava le 17 Juin 2016
Alicia, please contact MathWorks Technical Support.
The tools you are using to work with potentially corrupt files are intended for -v5 and -v7 MATLAB files, and not for -v7.3 files. -v7.3 files are a customized HDF5 format; sometimes they can be examined with HDF5 tools.
If you attach the .fig and associated .m files, I can try running it through some tools I have been developing. No promises, though, as the tools are not designed for the case where the .fig is a corrupted .mat .

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Large Files and Big Data dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by