Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用MATLAB批处理脚本与SPM预处理交互_Matlab - Fatal编程技术网

使用MATLAB批处理脚本与SPM预处理交互

使用MATLAB批处理脚本与SPM预处理交互,matlab,Matlab,我有一个脚本的问题,该脚本应该批处理功能磁共振成像数据的预处理管道。问题本身与成像无关,而是某种我无法解决的编码问题,无论我尝试将一个解决方案进行了多少次迭代 %----------------------------------------------------------------------- % MATLAB Preprocessing Script spm_jobman('initcfg'); spm('defaults','FMRI'); spm_jo

我有一个脚本的问题,该脚本应该批处理功能磁共振成像数据的预处理管道。问题本身与成像无关,而是某种我无法解决的编码问题,无论我尝试将一个解决方案进行了多少次迭代

%-----------------------------------------------------------------------
% MATLAB Preprocessing Script


    spm_jobman('initcfg');
    spm('defaults','FMRI');
    spm_jobman('run', matlabbatch);


    gender = { 'female' };
    subjs = { 'sub_06' 'sub_07' };
    subjs_xt = { 'SUB_006' 'SUB_007' };



%% SPM Preprocessing
for k = 1:length(subjs)


    matlabbatch{1}.spm.temporal.st.scans = {
        {
        'Z:\subject_data\' gender '\' subjs{k} '\Functional\' subjs_xt{k} '_run_1\run_1-t000-0001.nii,1'
...
        'Z:\subject_data\' gender '\' subjs{k} '\Functional\' subjs_xt{k} '_run_1\run_1-t000-0132.nii,1'
        }
        }';
    %%
    matlabbatch{1}.spm.temporal.st.nslices = 30;
    matlabbatch{1}.spm.temporal.st.tr = 2;
    matlabbatch{1}.spm.temporal.st.ta = 1.93333333333333;
    matlabbatch{1}.spm.temporal.st.so = [1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30];
    matlabbatch{1}.spm.temporal.st.refslice = 1;
    matlabbatch{1}.spm.temporal.st.prefix = 'a';
    matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1) = cfg_dep('Slice Timing: Slice Timing Corr. Images (Sess 1)', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','files'));
    matlabbatch{2}.spm.spatial.realign.estwrite.data{2}(1) = cfg_dep('Slice Timing: Slice Timing Corr. Images (Sess 2)', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{2}, '.','files'));
    matlabbatch{2}.spm.spatial.realign.estwrite.data{3}(1) = cfg_dep('Slice Timing: Slice Timing Corr. Images (Sess 3)', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{3}, '.','files'));
    matlabbatch{2}.spm.spatial.realign.estwrite.data{4}(1) = cfg_dep('Slice Timing: Slice Timing Corr. Images (Sess 4)', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{4}, '.','files'));
    matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.quality = 0.9;
    matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.sep = 4;
    matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.fwhm = 5;
    matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.rtm = 1;
    matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.interp = 2;
    matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.wrap = [0 0 0];
    matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.weight = '';
    matlabbatch{2}.spm.spatial.realign.estwrite.roptions.which = [0 1];
    matlabbatch{2}.spm.spatial.realign.estwrite.roptions.interp = 4;
    matlabbatch{2}.spm.spatial.realign.estwrite.roptions.wrap = [0 0 0];
    matlabbatch{2}.spm.spatial.realign.estwrite.roptions.mask = 1;
    matlabbatch{2}.spm.spatial.realign.estwrite.roptions.prefix = 'r';
    matlabbatch{3}.spm.spatial.coreg.estimate.ref(1) = cfg_dep('Realign: Estimate & Reslice: Mean Image', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','rmean'));
    matlabbatch{3}.spm.spatial.coreg.estimate.source = {'Z:\subject_data\' gender '\' subjs{k} '\Structural\T1-0001.nii,1'};
    matlabbatch{3}.spm.spatial.coreg.estimate.other = {''};
    matlabbatch{3}.spm.spatial.coreg.estimate.eoptions.cost_fun = 'nmi';
    matlabbatch{3}.spm.spatial.coreg.estimate.eoptions.sep = [4 2];
    matlabbatch{3}.spm.spatial.coreg.estimate.eoptions.tol = [0.02 0.02 0.02 0.001 0.001 0.001 0.01 0.01 0.01 0.001 0.001 0.001];
    matlabbatch{3}.spm.spatial.coreg.estimate.eoptions.fwhm = [7 7];
    matlabbatch{4}.spm.spatial.preproc.channel.vols(1) = cfg_dep('Coregister: Estimate: Coregistered Images', substruct('.','val', '{}',{3}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','cfiles'));
    matlabbatch{4}.spm.spatial.preproc.channel.biasreg = 0.001;
    matlabbatch{4}.spm.spatial.preproc.channel.biasfwhm = 60;
    matlabbatch{4}.spm.spatial.preproc.channel.write = [0 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(1).tpm = {'C:\Program Files\spm12\spm12\tpm\TPM.nii,1'};
    matlabbatch{4}.spm.spatial.preproc.tissue(1).ngaus = 1;
    matlabbatch{4}.spm.spatial.preproc.tissue(1).native = [1 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(1).warped = [0 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(2).tpm = {'C:\Program Files\spm12\spm12\tpm\TPM.nii,2'};
    matlabbatch{4}.spm.spatial.preproc.tissue(2).ngaus = 1;
    matlabbatch{4}.spm.spatial.preproc.tissue(2).native = [1 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(2).warped = [0 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(3).tpm = {'C:\Program Files\spm12\spm12\tpm\TPM.nii,3'};
    matlabbatch{4}.spm.spatial.preproc.tissue(3).ngaus = 2;
    matlabbatch{4}.spm.spatial.preproc.tissue(3).native = [1 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(3).warped = [0 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(4).tpm = {'C:\Program Files\spm12\spm12\tpm\TPM.nii,4'};
    matlabbatch{4}.spm.spatial.preproc.tissue(4).ngaus = 3;
    matlabbatch{4}.spm.spatial.preproc.tissue(4).native = [1 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(4).warped = [0 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(5).tpm = {'C:\Program Files\spm12\spm12\tpm\TPM.nii,5'};
    matlabbatch{4}.spm.spatial.preproc.tissue(5).ngaus = 4;
    matlabbatch{4}.spm.spatial.preproc.tissue(5).native = [1 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(5).warped = [0 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(6).tpm = {'C:\Program Files\spm12\spm12\tpm\TPM.nii,6'};
    matlabbatch{4}.spm.spatial.preproc.tissue(6).ngaus = 2;
    matlabbatch{4}.spm.spatial.preproc.tissue(6).native = [0 0];
    matlabbatch{4}.spm.spatial.preproc.tissue(6).warped = [0 0];
    matlabbatch{4}.spm.spatial.preproc.warp.mrf = 1;
    matlabbatch{4}.spm.spatial.preproc.warp.cleanup = 1;
    matlabbatch{4}.spm.spatial.preproc.warp.reg = [0 0.001 0.5 0.05 0.2];
    matlabbatch{4}.spm.spatial.preproc.warp.affreg = 'mni';
    matlabbatch{4}.spm.spatial.preproc.warp.fwhm = 0;
    matlabbatch{4}.spm.spatial.preproc.warp.samp = 3;
    matlabbatch{4}.spm.spatial.preproc.warp.write = [0 1];
    matlabbatch{5}.spm.spatial.normalise.write.subj(1).def(1) = cfg_dep('Segment: Forward Deformations', substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','fordef', '()',{':'}));
    matlabbatch{5}.spm.spatial.normalise.write.subj(1).resample(1) = cfg_dep('Realign: Estimate & Reslice: Realigned Images (Sess 1)', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','sess', '()',{1}, '.','cfiles'));
    matlabbatch{5}.spm.spatial.normalise.write.subj(2).def(1) = cfg_dep('Segment: Forward Deformations', substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','fordef', '()',{':'}));
    matlabbatch{5}.spm.spatial.normalise.write.subj(2).resample(1) = cfg_dep('Realign: Estimate & Reslice: Realigned Images (Sess 2)', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','sess', '()',{2}, '.','cfiles'));
    matlabbatch{5}.spm.spatial.normalise.write.subj(3).def(1) = cfg_dep('Segment: Forward Deformations', substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','fordef', '()',{':'}));
    matlabbatch{5}.spm.spatial.normalise.write.subj(3).resample(1) = cfg_dep('Realign: Estimate & Reslice: Realigned Images (Sess 3)', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','sess', '()',{3}, '.','cfiles'));
    matlabbatch{5}.spm.spatial.normalise.write.subj(4).def(1) = cfg_dep('Segment: Forward Deformations', substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','fordef', '()',{':'}));
    matlabbatch{5}.spm.spatial.normalise.write.subj(4).resample(1) = cfg_dep('Realign: Estimate & Reslice: Realigned Images (Sess 4)', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','sess', '()',{4}, '.','cfiles'));
    matlabbatch{5}.spm.spatial.normalise.write.woptions.bb = [-78 -112 -70
        78 76 85];
    matlabbatch{5}.spm.spatial.normalise.write.woptions.vox = [2 2 2];
    matlabbatch{5}.spm.spatial.normalise.write.woptions.interp = 4;
    matlabbatch{6}.spm.spatial.smooth.data(1) = cfg_dep('Normalise: Write: Normalised Images (Subj 1)', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','files'));
    matlabbatch{6}.spm.spatial.smooth.fwhm = [8 8 8];
    matlabbatch{6}.spm.spatial.smooth.dtype = 0;
    matlabbatch{6}.spm.spatial.smooth.im = 0;
    matlabbatch{6}.spm.spatial.smooth.prefix = 's';
    matlabbatch{7}.spm.spatial.smooth.data(1) = cfg_dep('Normalise: Write: Normalised Images (Subj 2)', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{2}, '.','files'));
    matlabbatch{7}.spm.spatial.smooth.fwhm = [8 8 8];
    matlabbatch{7}.spm.spatial.smooth.dtype = 0;
    matlabbatch{7}.spm.spatial.smooth.im = 0;
    matlabbatch{7}.spm.spatial.smooth.prefix = 's';
    matlabbatch{8}.spm.spatial.smooth.data(1) = cfg_dep('Normalise: Write: Normalised Images (Subj 3)', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{3}, '.','files'));
    matlabbatch{8}.spm.spatial.smooth.fwhm = [8 8 8];
    matlabbatch{8}.spm.spatial.smooth.dtype = 0;
    matlabbatch{8}.spm.spatial.smooth.im = 0;
    matlabbatch{8}.spm.spatial.smooth.prefix = 's';
    matlabbatch{9}.spm.spatial.smooth.data(1) = cfg_dep('Normalise: Write: Normalised Images (Subj 4)', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{4}, '.','files'));
    matlabbatch{9}.spm.spatial.smooth.fwhm = [8 8 8];
    matlabbatch{9}.spm.spatial.smooth.dtype = 0;
    matlabbatch{9}.spm.spatial.smooth.im = 0;
    matlabbatch{9}.spm.spatial.smooth.prefix = 's';

end
代码显然相当长,但这是因为我试图让它在每次函数运行时使用132个文件。我已经能够在每次运行1个文件的情况下完成这项工作,但这还不够

我收到的错误是:

 ??? Undefined function or variable 'matlabbatch'.

Error in ==> batch_preprocessing_old at 17
    spm_jobman('run', matlabbatch);

有关如何解决此问题的任何帮助?

与matlab相关的问题是,您的脚本引用了名为
matlabbatch
的变量,但未对其进行定义。如果这确实是一个matlab脚本,而不是函数的一部分,那么您应该更早地加载该变量(从
.mat
文件),将其放在基本工作区中,或者以其他方式构造它


生成有效的
matlabbatch
的行为与
spm
相关。如果您还没有这样做,请查看。第39.1.4节预处理的自动化似乎描述了该做什么。如果没有,请参阅手册前面的某个地方。由于这假设您熟悉
spm
本身,因此我自己并没有试图解决它。

与matlab相关的问题是,您的脚本引用了一个名为
matlabbatch
的变量,而没有定义它。如果这确实是一个matlab脚本,而不是函数的一部分,那么您应该更早地加载该变量(从
.mat
文件),将其放在基本工作区中,或者以其他方式构造它


生成有效的
matlabbatch
的行为与
spm
相关。如果您还没有这样做,请查看。第39.1.4节预处理的自动化似乎描述了该做什么。如果没有,请参阅手册前面的某个地方。由于这假设我对
spm
本身很熟悉,所以我自己并没有想办法弄清楚。

我发现这一点有点晚了,虽然可能与OP无关,但我想我会提供一个答案,以防其他人遇到这一问题。问题可能是第17行spm_jobman('run',matlabbatch')对spm_jobman的调用在定义matlabbatch之前编写。不需要加载先前的.mat文件;提供的代码应该在结构完整的情况下正确定义matlabbatch。在声明完成之前,您不能调用spm_jobman来运行它。将该行移到脚本的底部

我发现这一点有点晚了,虽然可能与OP无关,但我想我会提供一个答案,以防其他人发现这一点。问题可能是第17行spm_jobman('run',matlabbatch')对spm_jobman的调用在定义matlabbatch之前编写。不需要加载先前的.mat文件;提供的代码应该在结构完整的情况下正确定义matlabbatch。在声明完成之前,您不能调用spm_jobman来运行它。将该行移到脚本的底部

你熟悉matlab吗?无论如何,您的语法很好,但是您需要一个名为
matlabbatch
的变量以及适当的字段来运行此操作。例如,我在online call
load toy\u batch
中找到了一个例子,它提供了这样一个变量。。。关于您的问题还有更多详细信息吗?当我这样做时,我会得到以下错误:
警告:未知扩展名:spm_jobman中的“matlabbatch”>在spm_jobman中加载347处的spm_jobman中加载142处的spm_jobman中加载142处的“matlabbatch”>在spm_jobman中加载356处的作业批次预处理在17???在245使用==>spm_jobman时出错没有有效作业。错误==>批处理预处理旧版17
我希望我知道更多关于spm\U jobman在做什么,这样我可以提供更多的输入。。。以这种方式进行spm批处理的文献很少。您熟悉matlab吗?无论如何,您的语法很好,但是您需要一个名为
matlabbatch
的变量以及适当的字段来运行此操作。例如,我在online call
load toy\u batch
中找到了一个例子,它提供了这样一个变量。。。关于您的问题还有更多详细信息吗?当我这样做时,我会得到以下错误:
警告:未知扩展名:spm_jobman中的“matlabbatch”>在spm_jobman中加载347处的spm_jobman中加载142处的spm_jobman中加载142处的“matlabbatch”>在spm_jobman中加载356处的作业批次预处理在17???在245使用==>spm_jobman时出错没有有效作业。错误==>批处理预处理旧版17
我希望我知道更多关于spm\U jobman在做什么,这样我可以提供更多的输入。。。以这种方式进行spm配料的文献很少。这应该是公认的答案。这不是一个与SPM相关的问题,而是一个简单的编程错误。这应该是公认的答案。这不是一个与SPM相关的问题,而是一个简单的编程错误。