"Attempt to reference field of non-structure array" when reading in from a text file using spm_read_vols
2 views (last 30 days)
Show older comments
Charlotte Chaze
on 24 Nov 2015
Answered: Walter Roberson
on 25 Nov 2015
I have a list of nifti files that I want to read in from a text file rather than inputting every nifti in the script. I'm trying to get the first timepoint for each nifti file. When I try this command, where '10niftis.txt' is my list of niftis,
data = spm_read_vols('10niftis.txt, 1');
I get the error message "Attempt to reference field of non-structure array".
Any ideas? I'm not sure if I can use textread because I only want the first timepoint within each file.
0 Comments
Accepted Answer
Walter Roberson
on 25 Nov 2015
I do not know about getting the first time point of each file, but you are using spm_read_vols incorrectly. It should be something like:
fid = fopen('10niftis.txt', 'rt');
K = 0;
while true
this_nifti = fgetl(fid);
if ~ischar(this_nifti); break; end %end of file detected
K = K + 1;
V{K} = spm_vol(this_nifti);
data{K} = spm_read_vols(V{K});
end
fclose(fid);
Maybe you can use
data{K} = spm_read_vols(V{K}(1));
to read only the first time-point -- I have not researched the representation of spm volumes.
0 Comments
More Answers (0)
See Also
Categories
Find more on MRI 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!