Run spm_jobman for 1st level fmri analysis with multiple sessions per participant
34 次查看(过去 30 天)
显示 更早的评论
I'm trying to run a 1st level analysis using spm_jobman, however I'm unsure how to construct 'jobs' so that it compiles 4 sessions (or runs) for each participant. Below is my code, looping over 2 participants. The code works if I were to only run 1 session per participant, but as for 4 sessions I get an error in spm_jobman('run', jobs, inputs{:}):
Error using regexp
All cells must be char row vectors.
p = [01 02]; %loop over 2 participants
for p=p
p = num2str(p,'%02d');
matlabbatch{1}.spm.stats.fmri_spec.dir = {['C:\Users\LG\Preprocessed\sub-' p '\func']};
matlabbatch{1}.spm.stats.fmri_spec.timing.units = 'secs';
matlabbatch{1}.spm.stats.fmri_spec.timing.RT = 1.45;
matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t = 16;
matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t0 = 8;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% RUN 1
matlabbatch{1}.spm.stats.fmri_spec.sess(1).scans = {
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,1']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,2']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,3']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,4']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,5']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,6']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,7']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,8']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,9']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,10']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,11']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,12']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,13']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,14']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,15']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,16']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,17']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,18']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,19']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-01.nii,20']
};
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(1).cond(1).name = 'response';
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(1).cond(1).onset = [60.90929549
104.6000811
155.1496962
204.8101424
250.1017262
300.3133727];
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(1).cond(1).duration = 3;
matlabbatch{1}.spm.stats.fmri_spec.sess(1).cond(1).tmod = 0;
matlabbatch{1}.spm.stats.fmri_spec.sess(1).cond(1).pmod = struct('name', {}, 'param', {}, 'poly', {});
matlabbatch{1}.spm.stats.fmri_spec.sess(1).cond(1).orth = 1;
matlabbatch{1}.spm.stats.fmri_spec.sess(1).multi = {''};
matlabbatch{1}.spm.stats.fmri_spec.sess(1).regress = struct('name', {}, 'val', {});
matlabbatch{1}.spm.stats.fmri_spec.sess(1).multi_reg = {['C:\Users\LG\Preprocessed\Regressors\sub-' p '_regressors_run-01.txt']};
matlabbatch{1}.spm.stats.fmri_spec.sess(1).hpf = 128;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% RUN 2
matlabbatch{1}.spm.stats.fmri_spec.sess(2).scans = {
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,1']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,2']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,3']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,4']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,5']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,6']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,7']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,8']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,9']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,10']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,11']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,12']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,13']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,14']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,15']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,16']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,17']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,18']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,19']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-02.nii,20']
};
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(2).cond(1).name = 'response';
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(2).cond(1).onset = [52.11927195
100.4474076
140.7837058
184.2565347
233.6373778
278.7443659];
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(2).cond(1).duration = 3;
matlabbatch{1}.spm.stats.fmri_spec.sess(2).cond(1).tmod = 0;
matlabbatch{1}.spm.stats.fmri_spec.sess(2).cond(1).pmod = struct('name', {}, 'param', {}, 'poly', {});
matlabbatch{1}.spm.stats.fmri_spec.sess(2).cond(1).orth = 1;
matlabbatch{1}.spm.stats.fmri_spec.sess(2).multi = {''};
matlabbatch{1}.spm.stats.fmri_spec.sess(2).regress = struct('name', {}, 'val', {});
matlabbatch{1}.spm.stats.fmri_spec.sess(2).multi_reg = {['C:\Users\LG\Preprocessed\Regressors\sub-' p '_regressors_run-02.txt']'};
matlabbatch{1}.spm.stats.fmri_spec.sess(2).hpf = 128;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% RUN 3
matlabbatch{1}.spm.stats.fmri_spec.sess(3).scans = {
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,1']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,2']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,3']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,4']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,5']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,6']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,7']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,8']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,9']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,10']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,11']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,12']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,13']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,14']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,15']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,16']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,17']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,18']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,19']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-03.nii,20']
};
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(3).cond(1).name = 'response';
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(3).cond(1).onset = [57.25576395
101.9315581
145.8371098
191.9116843
244.1439597
291.8380025];
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(3).cond(1).duration = 3;
matlabbatch{1}.spm.stats.fmri_spec.sess(3).cond(1).tmod = 0;
matlabbatch{1}.spm.stats.fmri_spec.sess(3).cond(1).pmod = struct('name', {}, 'param', {}, 'poly', {});
matlabbatch{1}.spm.stats.fmri_spec.sess(3).cond(1).orth = 1;
matlabbatch{1}.spm.stats.fmri_spec.sess(3).multi = {''};
matlabbatch{1}.spm.stats.fmri_spec.sess(3).regress = struct('name', {}, 'val', {});
matlabbatch{1}.spm.stats.fmri_spec.sess(3).multi_reg = {['C:\Users\LG\Preprocessed\Regressors\sub-' p '_regressors_run-03.txt']};
matlabbatch{1}.spm.stats.fmri_spec.sess(3).hpf = 128;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% RUN 4
matlabbatch{1}.spm.stats.fmri_spec.sess(4).scans = {
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,1']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,2']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,3']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,4']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,5']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,6']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,7']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,8']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,9']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,10']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,11']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,12']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,13']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,14']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,15']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,16']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,17']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,18']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,19']
['C:\Users\LG\Preprocessed\sub-' p '\func\sub-' p '_run-04.nii,20']
};
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(4).cond(1).name = 'response';
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(4).cond(1).onset = [55.53799317
106.2515497
154.7802451
201.6519239
248.3651463
291.0552334];
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(4).cond(1).duration = 3;
matlabbatch{1}.spm.stats.fmri_spec.sess(4).cond(1).tmod = 0;
matlabbatch{1}.spm.stats.fmri_spec.sess(4).cond(1).pmod = struct('name', {}, 'param', {}, 'poly', {});
matlabbatch{1}.spm.stats.fmri_spec.sess(4).cond(1).orth = 1;
%%
matlabbatch{1}.spm.stats.fmri_spec.sess(4).multi = {''};
matlabbatch{1}.spm.stats.fmri_spec.sess(4).regress = struct('name', {}, 'val', {});
matlabbatch{1}.spm.stats.fmri_spec.sess(4).multi_reg = {['C:\Users\LG\Preprocessed\Regressors\sub-' p '_regressors_run-04.txt']};
matlabbatch{1}.spm.stats.fmri_spec.sess(4).hpf = 128;
matlabbatch{1}.spm.stats.fmri_spec.fact = struct('name', {}, 'levels', {});
matlabbatch{1}.spm.stats.fmri_spec.bases.hrf.derivs = [0 0];
matlabbatch{1}.spm.stats.fmri_spec.volt = 1;
matlabbatch{1}.spm.stats.fmri_spec.global = 'None';
matlabbatch{1}.spm.stats.fmri_spec.mthresh = 0.8;
matlabbatch{1}.spm.stats.fmri_spec.mask = {''};
matlabbatch{1}.spm.stats.fmri_spec.cvi = 'AR(1)';
%%%%%% RUN 1st level analysis
jobfile={['C:\Users\LG\Preprocessed\sub-' p '\func\1stlevel.mat']};
save(char(jobfile), 'matlabbatch');
jobs =repmat(jobfile, 1, 4);
inputs = cell(0, 4);
for crun = 1:nrun
end
spm('defaults', 'FMRI');
spm_jobman('run', jobs, inputs{:});
clear matlabbatch;
end
0 个评论
回答(1 个)
Sai Pavan
2024-1-23
Hello,
I understand that you are trying to resolve the issue with first-level fMRI analysis job for SPM, with 4 sessions per participant.
The issue could be resolved by running `spm_jobman` with a single job per participant. The `jobs` variable is being set to repeat the same job file four times, which is not necessary and is likely causing the error you're encountering. You should be running `spm_jobman` with a single job per participant as each job already contains the four sessions. Also, the loop `for crun = 1:nrun` doesn't seem to be doing anything, as `nrun` is not defined and the loop body is empty.
Please refer to the corrected version of the code:
p = [01 02]; % loop over 2 participants
for i = 1:length(p)
participant = num2str(p(i),'%02d');
matlabbatch = {}; % Initialize the matlabbatch for each participant
% ... (rest of the code to set up matlabbatch) ...
%%%%%% RUN 1st level analysis
jobfile = {['C:\Users\LG\Preprocessed\sub-' participant '\func\1stlevel.mat']};
save(char(jobfile), 'matlabbatch');
spm('defaults', 'FMRI');
spm_jobman('run', jobfile);
clear matlabbatch;
end
Hope it helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Options at Command Line Only 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!