Code covered by the BSD License  

Highlights from
MATZEROFIX - shows you how to recover a MAT file with an R14 FCS - specific load error

5.0

5.0 | 1 rating Rate this file 8 Downloads (last 30 days) File Size: 3.33 KB File ID: #7058

MATZEROFIX - shows you how to recover a MAT file with an R14 FCS - specific load error

by

 

04 Mar 2005 (Updated )

Fix load error due to zero size in variable tag in MAT-File saved with R14 FCS MATLAB 7.0.

| Watch this File

File Information
Description

This tool is intended to show you how to fix v5 MAT-Files saved ONLY with R14FCS MATLAB 7.0.0, which the MATCAT tool determined to have zero size in the tag of a variable. This tool does not modify the MAT-File unless you use the optional second input argument, 'fix', in which case the file is fixed automatically, but only for the first (most common) case shown below.

The zero-size-in-tag issue has two possible causes:

(1) the most likely cause is specific to MATLAB 7.0.0, which only happens in rare cases, and is fixed in R14sp1, and thus can be avoided altogether by using MATLAB 7.0.1 or later (R14sp1 or later). If this is the cause of the zero tag in your MAT-File, then this tool (matzerofix) can either show you how to fix it yourself, or fix the MAT-File automatically.

The data of such a zero-size-in-tag variable is saved correctly, only the variable's tag says zero data bytes (incorrect), thus causing MATLAB to be unable to load the file. Once the MAT-File is fixed by setting the correct size in the tag, the file will load correctly in MATLAB.

(2) the other possible cause is specific to MATLAB 7.0.0 through 7.0.4 and is due to a variable that is skipped during save. In this case, an extra 8 byte tag which should not be there is saved in the MAT-File. This will be fixed in R14sp3. This tool (matzerofix) does not fix this problem.

To fix such a file, the file must be copied to a new file, excluding the 8 byte tag at the offset indicated by matzerofix. For example, if you have a 200 byte MAT-File with a zero tag at offset 128, copy bytes 0-127 to a new file, skip bytes 128-135, then continue with bytes 136 until the end of the file. If there are more such tags, you may need to repeat the process until all are excluded, then it will load correctly in MATLAB.

Usage:

  matzerofix mymatfile.mat
  matzerofix('mymatfile.mat')
  matzerofix mymatfile.mat fix
  matzerofix('mymatfile.mat','fix')

You should download the MATCAT tool and diagnose your MAT-File first
to determine whether you need to use this (MATZEROFIX) tool on your file.

Sample output:

>> matzerofix myfile.mat
byte 128 compressed var size offset 132 data bytes 82
byte 218 compressed var size offset 222 data bytes 0 <-INCORRECT
correct this value like this:
fid=fopen('myfile.mat','r+','b');fseek(fid,222,'bof');fwrite(fid,82,'int32');fclose(fid)
byte 308 compressed var size offset 312 data bytes 339
>>

Acknowledgements

Matcat Mat File Corruption Analysis Tool and Matzerofix Shows You How To Recover A Mat File With An R14 Fcs Specific Load Error inspired this file.

This file inspired Matcat Mat File Corruption Analysis Tool and Matzerofix Shows You How To Recover A Mat File With An R14 Fcs Specific Load Error.

MATLAB release MATLAB 7 (R14)
Other requirements R14 FCS MATLAB 7.0.0 specific load error issue
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
23 Feb 2007 ana flesia

thank you

13 May 2005 R H

I can't seem to get this to run...?

Potentially related: when I downloaded it, it had many extra carriage returns in it that I had to delete manually.

Updates
11 Mar 2005

description updated

Contact us