Problem Loading a Design Matrix File

I am attempting to load a design matrix titled R_Hipp_all.mat into Matlab. However, all I'm getting are errors. If I click on the file, I get the following error:
Error using load
Number of columns on line 3 of ASCII file /Users/paigeoden/data/R_Hipp_all.mat
must be the same as previous lines.
Error in uiimport/runImportdata (line 465)
datastruct = load('-ascii', fileAbsolutePath);
Error in uiimport/gatherFilePreviewData (line 433)
[datastruct, textDelimiter, headerLines]=
runImportdata(fileAbsolutePath, type);
Error in uiimport (line 244)
gatherFilePreviewData(fileAbsolutePath);
If I try to open it within Matlab, I recieve this error:
load('R_Hipp_all.mat')
Error using load
Unable to read MAT-file /Users/paigeoden/data/R_Hipp_all.mat. Not a binary MAT-file.
Try load -ASCII to read as text.
Along with the bottom left box saying "Error loading the selected Matlab file." Does anyone know why this might be happening?

Answers (1)

dpb
dpb on 4 Jun 2019
The first error message tells you precisely why it's happening -- the third line of the file doesn't have the same number of values/delimiters as do the previous two lines. load -ascii can only handle regular files.
Whoever named the file with a .mat extension erred in doing so as it leads to expectations of what file content will be that aren't met with this particular file.
We would have to see the file to be able to have any more suggestions regarding how to read it specifically; in general there is textscan for fscanf which can read most any file structure but have to be coached on how to do so if the data isn't totally regular in pattern.

4 Comments

Thank you for your response! neither textscan nor fscanf work, unfortunately. The file was generated by the GLM gui in fsl, which may also be where the issue is coming from, in which case I may have to take my issue elsewhere.
I've attached the file to see if you may be able to figure it out.
The file has headers...
/NumWaves 3
/NumPoints 63
/PPheights 1.000000e+00 1.000000e+00 1.000000e+00
/Matrix
0.000000e+00 0.000000e+00 1.000000e+00
0.000000e+00 0.000000e+00 1.000000e+00
1.000000e+00 0.000000e+00 0.000000e+00
...
and as the error message says, the third record has four elements where the first two had only two...
This is trivial to read with one of several ways--
  1. The 'headerlines'',5 option in textscan
  2. or, optionally, use the comment type '/' to ignore the lines with slash as first character
  3. dlmread with the count to start row 4 (it's zero-based counting)
  4. importdata
  5. ...
But, to name a file a .mat file with a header structure is just wrong. I have no idea what any of the "the GLM gui in fsl" means other than the guess of what GLM typically means in regression analyses--but that doesn't really seem to fit the output here, either.
Thank you! This is probably a silly question, but how were you able to look at the file like that?
Well, I did that by simply clicking on your link and "open in new tab" -- but just use a text editor like any other text file...

Sign in to comment.

Products

Release

R2019a

Asked:

on 4 Jun 2019

Edited:

dpb
on 4 Jun 2019

Community Treasure Hunt

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

Start Hunting!