Error loading a just-saved matfile

I'm processing a bunch of participant files by saving a participant's data structure ('subjData') as a matfile, then later in the analysis pipeline I'm loading the matfiles again individually.
Saving is done using this code:
newFilename = strrep(origFilename,'.edf','.mat');
save(newFilename,'origFilename', 'subjData')
And loading is done using this code:
existingSubjMatfile = [dataDir parentfolder fname '.mat'];
load(existingSubjMatfile)
Loading works great for the first 15 or so files, then I get one of two errors when attempting to load certain files.
Error 1:
Error using load
Number of columns on line 2 of ASCII file 2003_18m/2003_18m.mat must be the same as previous lines.
Error in uiimport/runImportdata (line 461)
datastruct = load('-ascii', fileAbsolutePath);
Error in uiimport/gatherFilePreviewData (line 429)
[datastruct, textDelimiter, headerLines]= runImportdata(fileAbsolutePath, type);
Error in uiimport (line 246)
gatherFilePreviewData(fileAbsolutePath);
Error 2:
Error using load
Unable to read MAT-file 2004_02m/2004_02m.mat. Not a binary MAT-file. Try LOAD
-ASCII to read as text.
When I double click the matfiles I get the same error. I've inspected the data just before saving, and nothing appears different from the other files that load just fine. What's going wrong with these particular files? (They're only around 860 kb, so not the largest of the files I'm working with)

10 comentarios

Walter Roberson
Walter Roberson el 9 de Oct. de 2018
Why are you calling uiimport on a mat file?
Al_G
Al_G el 9 de Oct. de 2018
I’m not calling it is the odd thing, yet it shows up in the error message. I’m only using load to pull in the matfile
which -all load
Also we need the complete error message traceback, everything in red
Al_G
Al_G el 9 de Oct. de 2018
Hi Walter, sorry for the confusion. I got the cause of my errors mixed up.
The main error is Error 2, which occurs when running my code to process a few hundred files. Error 1 occurs when I give up and try to manually load one problematic file by double-clicking it.
The full-text of Error 1:
Error using load
Number of columns on line 2 of ASCII file 2003_18m/2003_18m.mat must be the same as previous
lines.
Error in uiimport/runImportdata (line 461)
datastruct = load('-ascii', fileAbsolutePath);
Error in uiimport/gatherFilePreviewData (line 429)
[datastruct, textDelimiter, headerLines]= runImportdata(fileAbsolutePath, type);
Error in uiimport (line 246)
gatherFilePreviewData(fileAbsolutePath);
The full text of Error 2:
Error using load
Unable to read MAT-file 2003_18m/2003_18m.mat. Not a binary MAT-file. Try LOAD -ASCII to read
as text.
This is the output when I type which -all load in the command window:
which -all load
built-in (/Applications/MATLAB_R2015b.app/toolbox/matlab/general/load)
load is a Java method % com.mathworks.services.Prefs method
load is a Java method % com.mathworks.jmi.ClassLoaderManager method
load is a Java method % java.lang.System method
/Applications/MATLAB_R2015b.app/toolbox/shared/reqmgt/+rmiml/@RmiMlData/RmiMlData.p % rmiml.RmiMlData method
/Applications/MATLAB_R2015b.app/toolbox/slvnv/reqmgt/+rmidata/@RmiData/RmiData.p % rmidata.RmiData method
/Applications/MATLAB_R2015b.app/toolbox/matlab/winfun/@COM/load.m % COM method
/Applications/MATLAB_R2015b.app/toolbox/idelink/extensions/eclipseide/@eclipseide/load.m % eclipseide method
/Applications/MATLAB_R2015b.app/toolbox/idelink/extensions/ticcs/@ccsdebug/load.m % ccsdebug method
I see you are using Mac. At the MATLAB level, please try
!file 2003_18m/2003_18m.mat
Whatever it is appears to not be a standard .mat file.
If !file just says something like "data" then please proceed to
!od -cx 2003_18m/2003_18m.mat | head
and show us the output.
Al_G
Al_G el 9 de Oct. de 2018
Editada: Al_G el 9 de Oct. de 2018
Generally speaking, how would it save as a non-standard matfile if all the ones I saved preceding it using the same lines of code saved as a standard file and load normally?
Typing the first line you gave returns "data". Typing the second line you gave returns:
!od -cx 2003_18m.mat | head
0000000 ȸ ** 363 # r X ś ** T 266 2 256 310 037 221 371
b8c8 23f3 5872 9bc5 b654 ae32 1fc8 f991
0000020 r \r 310 5 ! V 207 \ + 376 367 034 367 275 315 273
0d72 35c8 5621 5c87 fe2b 1cf7 bdf7 bbcd
0000040 306 374 356 P - 335 225 275 367 237 240 273 223 337 } <
fcc6 50ee dd2d bd95 9ff7 bba0 df93 3c7d
0000060 270 345 ( 306 د ** 234 261 \b 370 ۅ ** 211 201 ˟ **
e5b8 c628 afd8 b19c f808 85db 8189 9fcb
0000100 N 306 q 204 Q . 342 247 3 ' > 334 ' 276 233 021
c64e 8471 2e51 a7e2 2733 dc3e be27 119b
Walter Roberson
Walter Roberson el 9 de Oct. de 2018
That file format does not match anything I happen to recognize. It does not look to be single or double precision numbers either (not impossible, but the range would be rather unusual.)
I currently have no idea how that file got to be the way it is.
How was it created, and can you re-create it? And did it happen to be like the 64th or 240th or 256th file in a sequence that was being created?
Al_G
Al_G el 10 de Oct. de 2018
I divided a structure into a few smaller structures and performed some basic analysis steps to clean the data, then re-saved a subset into the matfile. Saving goes without a hitch.
When I try to run the next piece of code to load those just-saved files, of the first 35 files, I receive the error on the 15th 17th 19th 34th and 35th file.
When I re-run the pipeline, and re-save the files, the error still occurs for the same files as before.
Walter Roberson
Walter Roberson el 10 de Oct. de 2018
Can you post your code, and the 15th input?
Stephen23
Stephen23 el 10 de Oct. de 2018
@Al_G: please upload the actual code used, by clicking the paperclip button in a new comment.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Etiquetas

Preguntada:

el 8 de Oct. de 2018

Comentada:

el 10 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by