clear;clc parentdir = 'F:\data process\fMRI\fmrioutput'; % 定义储存各被试源文件的上级文件夹 cd(parentdir); % 进入这个上级文件夹 allsubjects = dir('sub*');%查找该文件夹下的所有被试 subinfos = numel(allsubjects); for i=1:numel(allsubjects) % 对每个被试进行循环 cursubject = allsubjects(i).name; % 找到当前被试的名字 matlabbatch=cell(1); curWPAT = fullfile(parentdir,cursubject,'WPAT'); curfucout=fullfile('F:\data process\fMRI\fmrioutput',cursubject,'WPAT') matlabbatch{1}.spm.stats.fmri_spec.dir = {curfucout}; matlabbatch{1}.spm.stats.fmri_spec.sess.scans = cellstr(spm_select('ExtFPList', curWPAT, '^sw*.nii', Inf)) matlabbatch{1}.spm.stats.fmri_spec.timing.units = 'scans'; matlabbatch{1}.spm.stats.fmri_spec.timing.RT = 2; matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t = 16; matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t0 = 8; %% matlabbatch{1}.spm.stats.fmri_spec.sess.cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {}); matlabbatch{1}.spm.stats.fmri_spec.sess.multi = {'D:\data process\fMRI\onsets\subject(i)_run1.mat'}; matlabbatch{1}.spm.stats.fmri_spec.sess.regress = struct('name', {}, 'val', {}); matlabbatch{1}.spm.stats.fmri_spec.sess.tempxx=dir(fullfile(curfucout,'rp*.txt')) matlabbatch{1}.spm.stats.fmri_spec.sess.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)'; matlabbatch{2}.spm.stats.fmri_est.spmmat(1) = cfg_dep('fMRI model specification: SPM.mat File', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat')); matlabbatch{2}.spm.stats.fmri_est.write_residuals = 0; matlabbatch{2}.spm.stats.fmri_est.method.Classical = 1; matlabbatch{3}.spm.stats.con.spmmat(1) = cfg_dep('Model estimation: SPM.mat File', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat')); matlabbatch{3}.spm.stats.con.consess{1}.tcon.name = 'Old'; matlabbatch{3}.spm.stats.con.consess{1}.tcon.weights = 1; matlabbatch{3}.spm.stats.con.consess{1}.tcon.sessrep = 'none'; matlabbatch{3}.spm.stats.con.delete = 0; end;怎么改
时间: 2023-11-22 07:55:20 浏览: 127
GCU-CLC-CloudApp:这是针对CLC项目@ GCU(CST-323)的
这段代码有几个语法错误,你可以试着按照下面的修改来运行:
```matlab
clear;clc;
parentdir = 'F:\data process\fMRI\fmrioutput'; % 定义储存各被试源文件的上级文件夹
cd(parentdir); % 进入这个上级文件夹
allsubjects = dir('sub*');%查找该文件夹下的所有被试
subinfos = numel(allsubjects);
for i=1:numel(allsubjects) % 对每个被试进行循环
cursubject = allsubjects(i).name; % 找到当前被试的名字
matlabbatch=cell(1);
curWPAT = fullfile(parentdir,cursubject,'WPAT');
curfucout=fullfile('F:\data process\fMRI\fmrioutput',cursubject,'WPAT');
matlabbatch{1}.spm.stats.fmri_spec.dir = {curfucout};
matlabbatch{1}.spm.stats.fmri_spec.sess.scans = cellstr(spm_select('ExtFPList', curWPAT, '^sw*.nii', Inf));
matlabbatch{1}.spm.stats.fmri_spec.timing.units = 'scans';
matlabbatch{1}.spm.stats.fmri_spec.timing.RT = 2;
matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t = 16;
matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t0 = 8;
%matlabbatch{1}.spm.stats.fmri_spec.sess.cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch{1}.spm.stats.fmri_spec.sess.multi = {['D:\data process\fMRI\onsets\' cursubject '_run1.mat']};
matlabbatch{1}.spm.stats.fmri_spec.sess.regress = struct('name', {}, 'val', {});
matlabbatch{1}.spm.stats.fmri_spec.sess.tempxx=dir(fullfile(curfucout,'rp*.txt'));
matlabbatch{1}.spm.stats.fmri_spec.sess.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)';
matlabbatch{2}.spm.stats.fmri_est.spmmat(1) = cfg_dep('fMRI model specification: SPM.mat File', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat'));
matlabbatch{2}.spm.stats.fmri_est.write_residuals = 0;
matlabbatch{2}.spm.stats.fmri_est.method.Classical = 1;
matlabbatch{3}.spm.stats.con.spmmat(1) = cfg_dep('Model estimation: SPM.mat File', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat'));
matlabbatch{3}.spm.stats.con.consess{1}.tcon.name = 'Old';
matlabbatch{3}.spm.stats.con.consess{1}.tcon.weights = 1;
matlabbatch{3}.spm.stats.con.consess{1}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 0;
spm_jobman('run',matlabbatch);
end
```
主要的修改如下:
1. 在 `curfucout` 赋值语句的末尾加上分号;
2. 在 `matlabbatch{1}.spm.stats.fmri_spec.sess.multi` 赋值语句中,使用字符串拼接的方式来生成文件路径;
3. 在 `matlabbatch{1}.spm.stats.fmri_spec.sess.tempxx` 赋值语句中,使用 `dir` 函数来列出相关文件;
4. 最后添加了一个 `spm_jobman` 函数来运行 `matlabbatch`。
阅读全文