fmri学习笔记|SPM 代码 循环

SPM 用代码跑操作(上)

提前说明一下,SPM中所有的操作都可以通过代码批量跑,逻辑都是一样的,下面举个最简单的例子,说一下整体的操作。
举例:假设需要做预处理中smooth的操作,共20个被试。

第一步生成脚本

我们一般操作都是通过SPM batch 窗口通过点点点进行需要的处理。
图一:X表示需要手动添加的内容,针对哪些image做后续的smooth。
图二:选择300个files。
图三:生成脚本,FIle<- save batch and script
图一
图一
在这里插入图片描述
图二
在这里插入图片描述
图三

第二步 看一下生成的脚本结构

生成脚本后会生成两个文件,temp_smooth 和 temp_smooth_job
在这里插入图片描述

temp_smooth_job

可以理解为temp_smooth_job文件是添加变量,比如要smooth哪些images,路径信息,平滑的一些参数,都是对变量进行赋值。
补充一下:这个赋值是将所有信息放到matlabbatch这个变量里,该变量是struct结构嵌套,如果想更好的理解,可以去学习了解一下Matlab中struct的数据类型的一些知识。
temp_smooth_job.m也可以直接跑,测试一下变量的赋值,只涉及变量赋值,不涉及SPM的操作。如下图
脚本内容 可以看到和batch窗口中信息是一一对应的
在这里插入图片描述
在这里插入图片描述
生成变量在这里插入图片描述
再补充一下SPM12 manual对job的解释
在这里插入图片描述

temp_smooth

先按照spm manual里说的方式解释一下怎么用代码跑。
temp_smooth是调用temp_smooth_job,跑smooth操作。
脚本内容
只解释用到的
L2跑循环的次数——这里举例有20个被试,nrun = 20
L3将temp_smooth_job的路径信息赋值进jobfile变量中
L4将jobfile信息进一步放到jobs中。
L6 输入信息,这里指job文件里要跑的image files(300个),跑循环就补充L6之后的内容,将每个被试的image files作为input
for crun = 1:nrun
% Named Directory Selector: Directory - cfg_files
inputs{1, crun} = MATLAB_CODE_TO_FILL_INPUT;
% Realign: Estimate & Reslice: Session - cfg_files
inputs{2, crun} = MATLAB_CODE_TO_FILL_INPUT;
% Coreg: Estimate: Source Image - cfg_files
inputs{3, crun} = MATLAB_CODE_TO_FILL_INPUT;

end
L9 跑smooth的操作,前面都算是准备步骤
在这里插入图片描述
补充一下SPM manual里的说明
Complete and run a pre-specified job
spm_jobman(’run’, job[, input1, input2 …])
This interface takes a job and asks for the input to any open configuration items one after another. If a list of appropriate inputs is supplied, these will be filled in. After all inputs are filled, the job will be run. Note that only items without a pre-set value will be filled (marked with <-X in the GUI). To force a item to to be filled, use “Edit:Clear Value” in the GUI or set its value to ’’ in the harvested job.
The job argument is very flexible, it can e.g. be a job variable, the name of a script creating a job variable, even a cell list of any mixture of variables and scripts. All job snippets found will be concatenated into a single job, the missing inputs will be filled and the resulting job will be run.
The batch system can generate a script skeleton for any loaded job. From the batch GUI, this feature is accessible via “File:Save Batch and Script”. This skeleton consists of a commented list of necessary inputs, a for loop to enter inputs for multiple runs or subjects and the code to initialise and run the job. An example is available in face_single_subject_script.m:

% List of open inputs
% Named Directory Selector: Directory - cfg_files
% Realign: Estimate & Reslice: Session - cfg_files
% Coreg: Estimate: Source Image - cfg_files
% fMRI model specification: Multiple conditions - cfg_files
nrun = X; % enter the number of runs here
jobfile = {fullfile(spm(’dir’),’man’,’batch’,’face_single_subject_template.m’)};
jobs = repmat(jobfile, 1, nrun);
inputs = cell(4, nrun);
for crun = 1:nrun
% Named Directory Selector: Directory - cfg_files
inputs{1, crun} = MATLAB_CODE_TO_FILL_INPUT;
% Realign: Estimate & Reslice: Session - cfg_files
inputs{2, crun} = MATLAB_CODE_TO_FILL_INPUT;
% Coreg: Estimate: Source Image - cfg_files
inputs{3, crun} = MATLAB_CODE_TO_FILL_INPUT;
% fMRI model specification: Multiple conditions - cfg_files
inputs{4, crun} = MATLAB_CODE_TO_FILL_INPUT;
end
spm(’defaults’,’fmri’);
spm_jobman(’run’,jobs,inputs{:});

The skeleton needs to be adapted to the actual data layout by adding MATLAB code which specifies the number of runs and the input data in the for loop.<

  • 5
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值