0001 function [D, changef] = add_trial_f(D)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if ~strcmp(modality(D), 'fmri')
0015 error('Can only set trial-specific F contrasts for FMRI designs');
0016 end
0017 SPM = des_struct(D);
0018 xX = SPM.xX;
0019
0020
0021
0022 if ~isfield(SPM,'Sess')
0023 changef = 0;
0024 return;
0025 end
0026
0027 Sess = SPM.Sess;
0028 xCon = [];
0029 if (Sess{1}.rep)
0030 for t = 1:length(Sess{1}.name)
0031 u = [];
0032 for s = 1:length(Sess)
0033 u = [u Sess{s}.col(Sess{s}.ind{t})];
0034 end
0035 q = 1:size(xX.X,2);
0036 q(u) = [];
0037 Fcname = Sess{s}.name{t};
0038 xcon = spm_FcUtil('Set',Fcname,'F','iX0',q,xX.xKXs);
0039 xCon = [xCon xcon];
0040 end
0041 else
0042 for s = 1:length(Sess)
0043 str = sprintf('Session %d: ',s);
0044 for t = 1:length(Sess{s}.name)
0045 q = 1:size(xX.X,2);
0046 q(Sess{s}.col(Sess{s}.ind{t})) = [];
0047 Fcname = [str Sess{s}.name{t}];
0048 xcon = spm_FcUtil('Set',Fcname,'F','iX0',q,xX.xKXs);
0049 xCon = [xCon xcon];
0050 end
0051 end
0052 end
0053
0054 [D Ic changef] = add_contrasts(D, xCon);