MATLAB: “Attempt to reference field of non-structure array” when reading in from a text file using spm_read_vols

arrayfmriniftispmspm_read_volstimepoint

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.

Best Answer

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.
Related Question