SPM使用程序进行批处理

注:
1.batch在SPM中保存(save batch and script)
2.运行batch不必在SPM中,在matlab界面点击上方绿色箭头Run即可
3.file=‘E:\Download\MRI_AD_TI_256256170\ADNI\test\data’;为数据文件夹位置,需要自己定义
4.for循环中i从3开始循环(前两个.和…跳过)
程序:
% List of open inputs
% Old Normalise: Estimate & Write: Source Image - cfg_files
% Old Normalise: Estimate & Write: Images to Write - cfg_files
nrun = 1; % enter the number of runs here %改成1即可
jobfile = {'C:\Users\SX\Desktop\spm_batch_test_job.m'}; %_job文件的位置
jobs = repmat(jobfile, 1, nrun); %不改
inputs = cell(2, nrun); %不改
% for crun = 1:nrun %整个程序只循环一次的话这一句可以注释掉
file='path\*.nii';%数据文件夹位置
file2=dir(file);%读取数据文件夹下的文件
n=length(file2);%读取数据文件夹下的文件数目
for i=1:n %
file3=strcat('path\',file2(i).name);%总路径
MATLAB_CODE_TO_FILL_INPUT=cellstr(file3); %改格式,改成胞体格式(输入需要)
inputs{1, 1} = MATLAB_CODE_TO_FILL_INPUT; % Old Normalise: Estimate & Write: Source Image - cfg_files
inputs{2, 1} = MATLAB_CODE_TO_FILL_INPUT; % Old Normalise: Estimate & Write: Images to Write - cfg_files
% end %crun改成1即可
spm('defaults', 'PET');
spm_jobman('run', jobs, inputs{:});
end %其余不变,整个程序为固定格式
353

被折叠的 条评论
为什么被折叠?



