<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>OneSubSess</title><revhistory><revision><revnumber>3</revnumber><date>2013-03-07 21:22:58</date><authorinitials>localhost</authorinitials><revremark>converted to 1.6 markup</revremark></revision><revision><revnumber>2</revnumber><date>2006-10-02 11:09:04</date><authorinitials>IanNimmoSmith</authorinitials></revision><revision><revnumber>1</revnumber><date>2006-10-02 11:06:26</date><authorinitials>IanNimmoSmith</authorinitials></revision></revhistory></articleinfo><screen><![CDATA[function one_sub_sess_model_moves5(MYV, sb, ss)
]]><![CDATA[
% check for defaults
global defaults
if isempty(defaults), spm_defaults; end
]]><![CDATA[
% store path
pwd_orig = pwd;
]]><![CDATA[
% condition stuff
condnames = MYV.cond_names;
nconds = length(condnames); 
]]><![CDATA[
% Names for movement parameters
move_names = {'x trans', 'y trans', 'z trans', ...
               'x rot', 'y rot', 'z rot'};
]]><![CDATA[
% Specify some design stuff
% Note that the TR must be the same for all runs in a model
TR                   = MYV.TRs(sb);             % seconds
SPM.xY.RT            = TR;      
]]><![CDATA[
% Specify design
%===========================================================================
% global normalization: OPTOINS:'Scaling'|'None'
%---------------------------------------------------------------------------
SPM.xGX.iGXcalc       = 'None';
]]><![CDATA[
% low frequency confound: high-pass cutoff (secs) [Inf = no filtering]
%---------------------------------------------------------------------------
SPM.xX.K(1).HParam    = MYV.hf_cut;
]]><![CDATA[
% intrinsic autocorrelations: OPTIONS: 'none'|'AR(1) + w'
%-----------------------------------------------------------------------
SPM.xVi.form       = 'AR(1) + w';
]]><![CDATA[
% basis functions and timing parameters
%---------------------------------------------------------------------------
% OPTIONS:'hrf'
%         'hrf (with time derivative)'
%         'hrf (with time and dispersion derivatives)'
%         'Fourier set'
%         'Fourier set (Hanning)'
%         'Gamma functions'
%         'Finite Impulse Response'
%---------------------------------------------------------------------------
% Fill in the field below with the corresponding string above
SPM.xBF.name       = 'hrf (with time derivative)';
%SPM.xBF.length     = 20;          % length in seconds - not used for hrf 
%SPM.xBF.order      = 1;           % order of basis set - not used for hrf
]]><![CDATA[
% The next two fields usually don't need changing. 
SPM.xBF.T          = 16;                % number of time bins per scan
SPM.xBF.T0         = 1;                 % first time bin (see slice
                                        % timing)
                        
% Selfish explanatory                                   
SPM.xBF.UNITS      = 'scans';           % OPTIONS: 'scans'|'secs' for
                                        % onsets
                        
% value of one means no Volterra pain                                   
SPM.xBF.Volterra   = 1;                 % OPTIONS: 1|2 = order of convolution
]]><![CDATA[
% specify filter for filenames
Filter             = MYV.snstats_filter;
]]><![CDATA[
% file list
PP = '';
]]><![CDATA[
% get, make, goto SPM results directory
sess_dir = fullfile(MYV.root, MYV.subjects{sb}, MYV.sesses{ss});  
ana_dir = fullfile(sess_dir, MYV.ana_dir);
if ~(exist(ana_dir))
  mkdir(sess_dir,MYV.ana_dir);
end
cd(ana_dir);
]]><![CDATA[
% file selection
P = spm_get('files',sess_dir,Filter);
SPM.nscan(1) = size(P,1);
PP = strvcat(PP,P);
]]><![CDATA[
% Condition stuff - onsets, durations, types.
c_ons = spm_load(MYV.cond_files{sb, ss});
[TRIAL_NO ONSET RESPONSE RESP_ONSET] = deal(1,2,3,4);
]]><![CDATA[
% now set into SPM design
for cno = 1:nconds
  tmp = c_ons(:, ONSET) -1;  % because we deleted the first scan
  
  % Make sure onsets are within scan range
  tempi = tmp >=0 & tmp <= size(P, 1);
  tmp = tmp(tempi);
 
  SPM.Sess.U(cno) = struct(...
      'ons', tmp,...
      'dur', ones(size(tmp)) * MYV.cond_dur * TR, ...
      'name',{condnames(cno)},...
      'P', struct('name','none')); % Parametric modulation
end
]]><![CDATA[
% design (user specified covariates)
%------------------------------------------------------------------
% realignment parameters to add to model
movefil = spm_get('Files', sess_dir, ...
                  ['rp_' MYV.sl_prefix '*.txt']);
moves = spm_load(movefil);
if isempty(moves)
  error(['Cannot get movement parameters from: ' sess_dir]);
end
  
% Fix goofy realignment params
moves = moves(1:size(P,1), :);
]]><![CDATA[
% mean centre moves
moves = moves - ones(size(P, 1), 1) * mean(moves);
move_diff = [zeros(1, 6); diff(moves)];
move_m1 = [zeros(1, 6); moves(1:end-1,:)];
]]><![CDATA[
% Put various params in
SPM.Sess.C.C    = [moves];
SPM.Sess.C.name = [move_names];
]]><![CDATA[
% set files
SPM.xY.P           = PP;
]]><![CDATA[
% Configure design matrix
SPMdes = spm_fmri_spm_ui(SPM);
]]><![CDATA[
% Estimate parameters
spm_unlink(fullfile('.', 'mask.img')); % avoid overwrite dialog
SPMest = spm_spm(SPMdes);
  
% back to initial directory
cd(pwd_orig);]]></screen></article>