help
help > RE: Help with Batch scripting using 3d nii files
Jul 25, 2012 07:07 PM | Alfonso Nieto-Castanon - Boston University
RE: Help with Batch scripting using 3d nii files
Hi Mac,
For your data structure something like the following should work:
nsubjects=175;
SubjectFolder=arrayfun(@(x)['/data/patients/x',num2str(x,'%03d')],1:nsubjects,'uni',0);
SessionSubFolder={'functional'};
for nsub=1:numel(SubjectFolder)
for nses=1:numel(SessionSubFolder)
files=dir(fullfile(SubjectFolder{nsub},SessionSubFolder{nses},'vol*.img'));
batch.New.functionals{nsub}{nses}={files(:).name};
fprintf('Subject %d, Session %d: %d functional files in %s\n',nsub,nses,numel(files),fullfile(SubjectFolder{nsub},SessionSubFolder{nses}));
end
endAnd regarding your question about the spm_vol error message, that error indicates simply that the file do not exist at the target location, typically this is the effect of some typo in the path or filename (perhaps the 3d files are named vol*.img instead of vol*.nii?), if there is some typo you should be able to type in the command line dir('/Volumes/My Passport/fMRI/FOG/RS T1s/FNFoff/Freezers/x002/functional/vol001.nii')and see a similar error, then go back and edit this line until you find the source of the problem.Let me know if this worksBestAlfonsoOriginally posted by Mac Shine:
For your data structure something like the following should work:
nsubjects=175;
SubjectFolder=arrayfun(@(x)['/data/patients/x',num2str(x,'%03d')],1:nsubjects,'uni',0);
SessionSubFolder={'functional'};
for nsub=1:numel(SubjectFolder)
for nses=1:numel(SessionSubFolder)
files=dir(fullfile(SubjectFolder{nsub},SessionSubFolder{nses},'vol*.img'));
batch.New.functionals{nsub}{nses}={files(:).name};
fprintf('Subject %d, Session %d: %d functional files in %s\n',nsub,nses,numel(files),fullfile(SubjectFolder{nsub},SessionSubFolder{nses}));
end
endAnd regarding your question about the spm_vol error message, that error indicates simply that the file do not exist at the target location, typically this is the effect of some typo in the path or filename (perhaps the 3d files are named vol*.img instead of vol*.nii?), if there is some typo you should be able to type in the command line dir('/Volumes/My Passport/fMRI/FOG/RS T1s/FNFoff/Freezers/x002/functional/vol001.nii')and see a similar error, then go back and edit this line until you find the source of the problem.Let me know if this worksBestAlfonsoOriginally posted by Mac Shine:
Hi Alfredo
Thanks for getting back to me so quickly.
To clarify your assumption, we only have one session per subject and they are in their own folder. The data structure is:
/data/patients/x001/functional
/structural
/data/patients/x002/functional
/structural
etc.
In that case, should I delete the lines related to "SessionSubFolder" (i.e. - lines 2, 4 and 7) as well as the other references to Sessions?
The other problem I'm having is that conn doesn't seem to want to recognise my .nii files. I know that they exist, as I can navigate to them and view them in SPM Display, however whenever I try to run the batch, I get the following error message:
??? Error using ==> spm_vol>subfunc at 111
File "/Volumes/My Passport/fMRI/FOG/RS T1s/FNFoff/Freezers/x002/functional/vol001.nii" does not exist.
Any ideas where I'm going wrong?
Mac
Thanks for getting back to me so quickly.
To clarify your assumption, we only have one session per subject and they are in their own folder. The data structure is:
/data/patients/x001/functional
/structural
/data/patients/x002/functional
/structural
etc.
In that case, should I delete the lines related to "SessionSubFolder" (i.e. - lines 2, 4 and 7) as well as the other references to Sessions?
The other problem I'm having is that conn doesn't seem to want to recognise my .nii files. I know that they exist, as I can navigate to them and view them in SPM Display, however whenever I try to run the batch, I get the following error message:
??? Error using ==> spm_vol>subfunc at 111
File "/Volumes/My Passport/fMRI/FOG/RS T1s/FNFoff/Freezers/x002/functional/vol001.nii" does not exist.
Any ideas where I'm going wrong?
Mac
Threaded View
| Title | Author | Date |
|---|---|---|
| Mac Shine | Jul 24, 2012 | |
| Alfonso Nieto-Castanon | Jul 25, 2012 | |
| Mac Shine | Jul 25, 2012 | |
| Alfonso Nieto-Castanon | Jul 25, 2012 | |
| Mac Shine | Jul 26, 2012 | |
| Alfonso Nieto-Castanon | Jul 27, 2012 | |
