forked from Pim-Mostert/decoding-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
designMatrix_dummy.m
40 lines (30 loc) · 1.08 KB
/
designMatrix_dummy.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
function design = designMatrix_dummy(cfg0, group)
% [design] = designMatrix_dummy(cfg, G)
% Returns a design matrix using dummy coding for the groups.
%
% G Array of length N, where N is the number of trials, that contains the group each trial
% belongs to, as identified by a unique number.
% cfg Configuration struct that can possess the following fields:
% .intercept = 'yes' or 'no' Whether to include an intercept or not.
% Default = 'no';
%
% design The design matrix of size G x N, where G is the number of G, containing the dummy codes.
%
% See also designMatrix_BH designMatrix_discriminant
% Created by Pim Mostert, 2016
if ~isfield(cfg0, 'intercept')
cfg0.intercept = 'no';
end
group = group(:);
GROUP = unique(group);
numG = length(GROUP);
numN = length(group);
design = zeros(numG, numN);
for iGroup = 1:numG
design(iGroup, group==GROUP(iGroup)) = 1;
end
% Include intercept
if strcmp(cfg0.intercept, 'yes')
design(1, :) = 1;
end
end