How to repair a corrupt mat file?

34 views (last 30 days)
Amelie Zeller
Amelie Zeller on 16 Aug 2023
Commented: Bruno Luong on 18 Aug 2023
Hello,
we have made measurements with a Bachmann controller and Simulink. More precisely, we used a Simulink block provided by Bachmann that allows to start and stop saving measurements to a .mat file. While saving, the .mat file located on the Bachmann memory "grows".
However, one time we did not stop the saving properly, but the connection to the sensors was interrupted and the saving was simply cancelled. Now we cannot load the .mat file into the Matlab workspace. The error message is "File might be corrupt".
Here we could not upload the .mat file because it is too big (268MB).
We would appreciate any advice on how to fix the corrupt .mat file. If necessary, we can of course try to make the .mat file available by other means.
Thank you very much!
Amelie
  6 Comments
dpb
dpb on 18 Aug 2023
Edited: dpb on 18 Aug 2023
"I tried to open the .mat file in a text editor..."
No, unless the -text flag is used, .mat files are an unformatted file; the only way to read them other than by TMW-supplied load or one of the FEX tools would be to use the file structure and read the raw data.
The first N bytes in a .mat file are text header that will identify the version, assuming the whole file has not been totally trashed somehow. try
type yourmatfile.mat
and see what it looks like -- first few lines followed by a bunch of gibberish. If it's large you might just read the first few lines and echo to the screen, or you should have been able to see the header in the text editor to identify at least the version.
There are routines in the external language interface section to read/write .mat files, whether they can be used on a corrupt file or whether they'll also barf on input checking first I don't know...
https://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf is a description of the version 4 (unlikely) and 5 file formats; for later versions I don't know that it is available.
Bruno Luong
Bruno Luong on 18 Aug 2023
IMO, the best chance is soliciting TMW consulting service to eventually recover your mat file.

Sign in to comment.

Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!