MATLAB: Loading large MAT files which are saved using “Save As” in Workspace gives error “File is corrupt”

MATLAB

In MATLAB Workspace, right click on the variable which you want to save and select "Save As". When you load the file again using "load" it gives the following error:
>> load('using_SaveAs.mat')
Error using load Unable to read MAT-file C:\Test\using_SaveAs.mat.
File might be corrupt

Best Answer

When you right click a variable in MATLAB Workspace and click "Save As", MATLAB runs the saving process in the background. Since the process is running in the background, we would have no way to know if the process is completed or not.
Loading a MAT file which is still being saved in the background or which was interrupted half way through because of closing MATLAB, results in the error.
Instead of using "Save As" in MATLAB Workspace, you can work around this issue by using the "save" command from the MATLAB Command Window.
For example, if you want to save the variable "April8Data"  in the file "April8Data.mat" use the following command:
>>save('April8Data.mat', 'April8Data', '-v7.3')
Also be sure to use the '-v7.3' flag when your variable size is >2GB.