forked from Pim-Mostert/decoding-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
designMatrix_discriminant.m
38 lines (29 loc) · 1.16 KB
/
designMatrix_discriminant.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
function design = designMatrix_discriminant(cfg0, group)
% [design] = designMatrix_dummy(cfg, G)
% Returns a design matrix using discriminant coding for two 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. G must consist entirely of two unique values.
% 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 discriminant codes.
%
% See also designMatrix_BH designMatrix_dummy
% Created by Pim Mostert, 2016
if ~isfield(cfg0, 'intercept')
cfg0.intercept = 'no';
end
group = group(:);
[GROUP, ~, design] = unique(group);
if length(GROUP) ~= 2
error('G must contain exaclty two unique values');
end
design = (design - 1)*2 - 1;
% Include intercept
if strcmp(cfg0.intercept, 'yes')
design = [ones(length(group), 1), design];
end
design = design';
end