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

Fix load error due to zero size in variable tag in MAT-File saved with R14 FCS MATLAB 7.0.
1.9K Downloads
Updated 1 Sep 2016

View License

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
>>

Cite As

John Aspinall (2024). MATZEROFIX - shows you how to recover a MAT file with an R14 FCS - specific load error (https://www.mathworks.com/matlabcentral/fileexchange/7058-matzerofix-shows-you-how-to-recover-a-mat-file-with-an-r14-fcs-specific-load-error), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Workspace Variables and MAT-Files in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.1

Updated license

1.0.0.0

the file was uploaded incorrectly causing the lines to wrap and certain characters to be displayed in hex, thus causing the code to not run