Why did my mat file corrupt? How can I recover it?
109 views (last 30 days)
Show older comments
I saved a matrix variable as a mat file on a GPU cluster (Linux, MATLAB R2019, GPU: Tesla V100) and tried to load it in my local PC (Windows10, MATLAB R2020a, CPU) but got the following error:
Error using load
Unable to read MAT-file C:\...\results\PSFs_seed0_v1_val5.mat. File might be corrupt.
I'm wondering what is causing this issue. My mat file can be downloaded from here. Below is the overview of my code to get this mat file:
clear all; close all;
seed = 0;
v = 1;
gpu_psf_save = zeros(N, N, num_samples, 'gpuArray');
for iter = 1:num_samples
gpu_psf_save(:,:,iter) = my_function(my_inputs);
end
% Retrieve from GPU to CPU
psf_save = gather(gpu_psf_save);
% Save as a mat file
name = sprintf('results/PSFs_seed%d_v%d_val5.mat', seed, v);
save(name, 'psf_save', '-v7.3');
I found some relevant posts but none of them solved my problem so far.
1. In this post: Unable to load, File may be corrupt, Jason mentioned that the use of cluster may be related to the problem:
"You mention that you are using a cluster. Is it possible that multiple processes are trying to write to the same file simultaneously? This will inevetabaly lead to corruption."
I'm using a cluster but I'm not using the save command simultaneously so this is probabliy not the reason for my corruption.
2. In this post: How do I recover data from a corrupt MAT-file?, the Mathworks support team provides the splitmat function to cope with this issue. I used this function and got the following:
splitmat PSFs_seed0_v1_val5
Found bad 0-byte size at variable #1.
ans =
0
Do you have any idea what caused the corruption? Not a few people have posted questions on this matter but has it been resolved? Note that I don't necessarily have to recover the mat file. Rather, I want to know how to avoid this problem.
1 Comment
Walter Roberson
on 14 Jan 2022
The splitmat function is only for -v7 and lower files, and does not apply to -v7.3 files.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!