"Attempt to reference field of non-structure array" when reading in from a text file using spm_read_vols

2 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Neuroimaging finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by