SPM batch script--multiple sessions; SYNTAX ERROR?
조회 수: 38 (최근 30일)
이전 댓글 표시
Hi, I'm thinking that I have a quick syntax error fix, but I cannot figure it out. I'm working with SPM12 batch scripts for preprocessing fMRI images.
Previously, I ran slice time correction using this code. I was just selecting 66 volumes for a file that ended in 005a001 for each person. This code worked fine for one run per person.
data_path = ['/Research Projects/flight/02_Nifti/',subjID,'/',timepoint,'/04_VEMP/combined_L_R'];
% Initialise SPM
spm('Defaults','fMRI');
spm_jobman('initcfg');
%select 66 volumes for first run
a = spm_select('ExtFPList', fullfile(data_path),'^.*005a001\.nii$',1:66);
clear matlabbatch
%Run slice timing
matlabbatch{1}.spm.temporal.st.scans = {cellstr(a)};
matlabbatch{1}.spm.temporal.st.nslices = 36;
matlabbatch{1}.spm.temporal.st.tr = 3.66;
matlabbatch{1}.spm.temporal.st.ta = 3.5583333333333;
matlabbatch{1}.spm.temporal.st.so = [2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35];
matlabbatch{1}.spm.temporal.st.refslice = 18;
matlabbatch{1}.spm.temporal.st.prefix = 'a';
spm_jobman('run',matlabbatch);
However, I wanted to edit this code to include two "sessions" (i.e., runs)--the first run ending in 005a001 and the second run ending in 007a001. Saving the batch code from clicking through the SPM GUI led me to believe that something like this would work:
data_path = ['/Research Projects/flight/02_Nifti/',subjID,'/',timepoint,'/04_VEMP/combined_L_R'];
%select 66 volumes for first run
a = spm_select('ExtFPList', fullfile(data_path),'^.*005a001\.nii$',1:66);
%select 66 volumes for second run
b = spm_select('ExtFPList', fullfile(data_path),'^.*007a001\.nii$',1:66);
clear matlabbatch
%Run slice timing
matlabbatch{1}.spm.temporal.st.scans = {
{cellstr(a)}
{cellstr(b)}
}';
matlabbatch{1}.spm.temporal.st.nslices = 36;
matlabbatch{1}.spm.temporal.st.tr = 3.66;
matlabbatch{1}.spm.temporal.st.ta = 3.5583333333333;
matlabbatch{1}.spm.temporal.st.so = [2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35];
matlabbatch{1}.spm.temporal.st.refslice = 18;
matlabbatch{1}.spm.temporal.st.prefix = 'a';
spm_jobman('run',matlabbatch);
However, when I run this I get the error that seems to indicate I'm not inputting the cell strings correctly, so this is likely just a syntax error on my fault?
Item 'Session', field 'val': Value must be either empty, a cellstr or a cfg_dep object.
Item 'Session', field 'val': Value must be either empty, a cellstr or a cfg_dep object.
댓글 수: 2
Cas Teurlings
2021년 6월 29일
편집: Cas Teurlings
2021년 6월 29일
Please gods of Matlab, give an answer to this question. I have exact the same!
답변 (2개)
Feng Lin
2019년 1월 15일
Hey, I have the same problem with you. I am wondering have you solved the issue or not? My scripts get errors all the time
댓글 수: 0
Elfriede Diestel
2021년 12월 23일
편집: Elfriede Diestel
2021년 12월 23일
I was able to solve this by creating a for loop around the first matlabbatch step. If, for example, their are two sessions (so sessions = {'1', '2'}), this is what the for loop would look like:
for i_data = 1:size(a,1)
for i_sess = 1:length(sessions)
if strcmp(sessions{i_sess}, '1')
matlabbatch{1}.spm.temporal.st.scans{i_sess}(i_data,1) = {a(i_data,:)};
end
if strcmp(sessions{i_sess}, '2')
matlabbatch{1}.spm.temporal.st.scans{i_sess}(i_data,1) = {b(i_data,:)};
end
end
end
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!