forked from OHBA-analysis/osl-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_beamformer_designmatrix.m
67 lines (50 loc) · 1.95 KB
/
setup_beamformer_designmatrix.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function x=setup_beamformer_designmatrix(S)
% creates a GLM design matrix
%
% Need S to contain:
% - Xsummary: a parsimonious description of the design matrix
% contains values Xsummary{reg,cond}, where reg is regressor no. and cond is condition no.
%
% - trialtypes: vector num_trials long indicating which condition each trial in the MEG data belongs to
% OR
% - Xsummary is the path to the text file containing the design matrix. That text file
% is num_trials x num_regressors, where the num_trials (and trial order) assumes that the D.badtrials trials have been removed.
% outputs the design matrix, x, which is num_trials x num_regressors
% - trial_rejects (optional) is a text file containing a list of trial indices ( indexed via the trial order in
% the loaded in design matrix ) to indicate any further trials ( above and beyond the D.badtrials trials )
% that you do not want to include in the analysis (e.g. for behavioural reasons), and which will get set to 0 in the design matrix.
%
% MWW 2011
if(isfield(S,'design_matrix')),
x=S.design_matrix;
else,
if(ischar(S.Xsummary)),
x=load(S.Xsummary);
if(isfield(S,'trial_rejects')),
trial_rejects=load(S.trial_rejects);
x(trial_rejects,:)=0;
end;
else,
if(~isfield(S,'trialtypes'))
if(isstr(S.res))
tmp=load(S.res);
res=tmp.res;
if(~isfield(res,'trialtypes'))
res=res{1};
end;
else
res=S.res;
end;
S.trialtypes=res.trialtypes;
end;
% Set up design matrix
x=[];
for d=1:size(S.Xsummary,2), % indexes regressor
regtmp=[];
for t=1:length(S.Xsummary{d}), % indexes trial type
regtmp(find(S.trialtypes==t))=S.Xsummary{d}(t);
end;
x(:,d)=regtmp;
end;
end;
end;