0001 function SPM = estimate_er_model(model_file, ev_con)
0002
0003
0004
0005
0006
0007
0008
0009
0010 if nargin < 1
0011 error('Need model filename');
0012 end
0013 if nargin < 2
0014 error('Need event contrast');
0015 end
0016
0017
0018 if ~exist(model_file, 'file')
0019 error(['Cannot find ' model_file]);
0020 end
0021 SPM = load(model_file);
0022 if isfield(SPM, 'SPM'), SPM=SPM.SPM; end
0023
0024
0025 nblocks = length(SPM.xX.iB);
0026 con = [repmat(ev_con, 1, nblocks) zeros(1, nblocks)]';
0027
0028
0029 swd = fileparts(model_file);
0030 pwd_orig = pwd;
0031
0032 switch spm('ver')
0033 case 'SPM99'
0034
0035 cd(swd);
0036 Sess=SPM.Sess; xsDes=SPM.xsDes;
0037 spm_spm(SPM.VY,SPM.xX,SPM.xM,SPM.F_iX0,Sess,xsDes);
0038
0039
0040 cd(pwd_orig);
0041 global SPM_BCH_VARS
0042 con_struct = struct('names', {{'stim_hrf'}},...
0043 'types', {{'T'}}, ...
0044 'values', {{con'}});
0045
0046
0047 m_file = 'er_contrast_spm99';
0048 ms = which(m_file);
0049 if isempty(ms)
0050 error(sprintf(['Hmm - can''t find %s on the path - maybe ' ...
0051 'you should run from the batch directory'], ...
0052 m_file))
0053 end
0054
0055 SPM_BCH_VARS = struct(...
0056 'work_dir', swd, ...
0057 'ana_type', 2, ...
0058 'm_file', ms, ...
0059 'contrasts', con_struct);
0060 spm_bch('do_bch_wrapper');
0061
0062 otherwise
0063
0064 if ~exist('defaults', 'var')
0065 global defaults;
0066 spm_defaults;
0067 end
0068
0069
0070 cd(swd);
0071 spm_unlink(fullfile('.', 'mask.img'));
0072 SPM = spm_spm(SPM);
0073
0074
0075 new_con = spm_FcUtil('Set','stim_hrf',...
0076 'T','c',con,SPM.xX.xKXs);
0077 if isempty(SPM.xCon)
0078 SPM.xCon = new_con;
0079 else
0080 SPM.xCon(end + 1) = new_con;
0081 end
0082 SPM = spm_contrasts(SPM);
0083
0084
0085 cd(pwd_orig);
0086 end
0087