Cannot open a structure file in Matlab

18 views (last 30 days)
Shannon on 25 Jun 2020
Commented: Monisha Nalluru on 15 Jul 2020
I'm operating Matlab2018a on a Windows 10 machine. I can create structure files, but cannot open them. I get this warning/error:
Warning: Unexpected end-of-file while reading compressed data
Error using load
Cannot read file Y:\....filneame.mat
The drive that I'm saving and opening from is a network drive. I have read/write permissions on this drive and can read other non-structure files with no issues.
Is there a solution for this?
Shannon on 26 Jun 2020
That's an understandable issue. I'll see if I can find a work-around. Thanks for your help.

Sign in to comment.

Answers (1)

Monisha Nalluru
Monisha Nalluru on 10 Jul 2020
The reason for this error might be due to MAT file corruption in the network drive.
Another indication of the MAT file being corrupt are error messages related to ‘HDF5’ appearing in MATLAB Command Window/Linux or MacOS Terminal/Windows Command prompt.
You can try to recover the non-corrupt portions or individual variables in the mat file using matfilecommand.
Consider for example that 'test.mat' has a variable 'v' that is unreadable. You can first get the size of this variable using the 'size' function as follows:
size(m,v) ans= 6 100
This tells us that the variable 'v' in 'test.mat' is a 2-D array which has 6 rows and 100 columns (a total of 600 values). You can then try to read the 'non-corrupt' values in 'v' and store them in a new array 'vRec' as follows :
vRec = zeros(6,100); % pre-allocate for efficiency
for i=1:6
for j=1:100
vRec(i,j) = m.v(i,j); % store the value if it is not corrupt;
vRec(i,j) = NaN; % if the value is corrupt/unreadable store 'NaN;
disp([int2str(i) ',' int2str(j) ' is unreadable.']); % display the indices of the unreadable elements
The above code will try to read all the 'non-corrupt' values in 'v' and store them in 'vRec'. The corrupt values in 'v' will be stored as 'NaNs'
Monisha Nalluru
Monisha Nalluru on 15 Jul 2020
Hi Shannon,
Can you check by saving the files in these version and check the load command, as I am not able to reproduce the error at my end.

Sign in to comment.


Find more on File Operations 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!