MATLAB: How do you load corrupt “v4” MAT files that produce error on using “load”

corruptloadmatfileMATLABv4

Best Answer

MAT files have restrictions on their structure based on the specific version of the MAT file being used. In the specific case of the "v4" version, the maximum number of elements in an array cannot exceed 100000000, and the size of each individual variable cannot exceed 2 GB as listed here:
If the load function shows errors regarding corrupt v4 files format, here are some possible workarounds you can try in order to resolve the issue:
1. It is possible that the file might be corrupted during the generation process. Please regenerate the file and try loading again to make sure that it is not the case.
2. Try loading specific variables from the existing v4 MAT file and then save all the variables into a new MAT file in the latest version. I have attached a script called "partial_load_save.m" which uses the "whos" command to figure out the variable names in the original v4 MAT file and then loads them into MATLAB one by one using a "for" loop and then saves the variables in the workspace into a new MAT file in the latest MAT file version.
You can learn more about the "whos" command and loading specific variables from a "matfile" in the following links: