-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspm_design_factorial.m
48 lines (43 loc) · 1.71 KB
/
spm_design_factorial.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function [I,P,H,Hnames] = spm_design_factorial(fd)
% Extract factorial matrix, file list and H partition of design matrix
% FORMAT [I,P,H,Hnames] = spm_design_factorial(fd)
%
% fd - structure defined in spm_cfg_factorial_design
% with fields fact and icell
%
% I - Nscan x 4 factor matrix
% P - List of scans
% H - Component of design matrix describing conditions
% Hnames - Condition names
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Will Penny, Guillaume Flandin
% $Id: spm_design_factorial.m 3860 2010-05-04 15:59:25Z guillaume $
% Get number of factors, levels and cells
%--------------------------------------------------------------------------
Nfactors = numel(fd.fact);
Nlevels = [fd.fact.levels];
Ncells = numel(fd.icell);
% Get file list and scan x factor matrix I
%--------------------------------------------------------------------------
I = [];
P = {};
for i=1:Ncells
nc = numel(fd.icell(i).scans);
I = [I; [[1:nc]', repmat(fd.icell(i).levels(:)',nc,1)]];
P = {P{:}, fd.icell(i).scans{:}}';
end
[I, A] = sortrows(I,2:Nfactors+1);
P = P(A);
I = [I ones(size(I,1),4-size(I,2))];
% Create H partition of design matrix
%--------------------------------------------------------------------------
[H,Hnames] = spm_DesMtx(I(:,2:Nfactors+1),'-',{fd.fact(:).name});
% Display some warnings
%--------------------------------------------------------------------------
if Ncells ~= prod(Nlevels)
disp('Some cell(s) are missing.');
end
if size(I,1) ~= size(unique(I,'rows'),1)
disp('Some cell(s) are defined several times.');
end