-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesign.m
84 lines (79 loc) · 3.1 KB
/
Design.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
classdef Design < handle
properties ( SetAccess = private)
num_scans;
num_conds;
cond_names;
onsets;
num_bins;
path;
end
methods
function obj = Design(onsets, num_bins, cond_names, num_scans)
if(size(cond_names,1) ~= size(onsets,1))
error('onsets must be a matrix of size (num_conds*num_onsets)');
end
if iscell(onsets)
for i = 1:size(onsets,1)
onsets{i} = ceil(onsets{i});
end
else
onsets = ceil(onsets);
end
obj.onsets = onsets;
obj.num_bins = num_bins;
obj.cond_names = cond_names;
obj.num_conds = size(cond_names,1);
obj.num_scans = num_scans;
end
function G = createG(obj)
if iscell(obj.onsets)
G = zeros(obj.num_scans, obj.num_bins*obj.num_conds);
for j = 1:obj.num_conds
cond_onsets = obj.onsets{j};
for i = 1:size(obj.onsets{j},2)
G(cond_onsets(i):cond_onsets(i)+obj.num_bins-1, ...
(j-1)*obj.num_bins+1:(j-1)*obj.num_bins+obj.num_bins) = ...
G(cond_onsets(i):cond_onsets(i)+obj.num_bins-1, ...
(j-1)*obj.num_bins+1:(j-1)*obj.num_bins+obj.num_bins)|...
eye(obj.num_bins);
end
end
else
G = zeros(obj.num_scans, obj.num_bins*obj.num_conds);
for j = 1:obj.num_conds
for i = 1:size(obj.onsets,2)
G(obj.onsets(j, i):obj.onsets(j,i)+obj.num_bins-1, ...
(j-1)*obj.num_bins+1:(j-1)*obj.num_bins+obj.num_bins) = ...
G(obj.onsets(j, i):obj.onsets(j,i)+obj.num_bins-1, ...
(j-1)*obj.num_bins+1:(j-1)*obj.num_bins+obj.num_bins)|...
eye(obj.num_bins);
end
end
end
end
% Remove eventually
function create_G(obj, dir, run_id)
G = zeros(obj.num_scans, obj.num_bins*obj.num_conds);
for j = 1:obj.num_conds
for i = 1:size(obj.onsets,2)
G(obj.onsets(j, i):obj.onsets(j,i)+obj.num_bins-1, ...
(j-1)*obj.num_bins+1:(j-1)*obj.num_bins+obj.num_bins) = ...
G(obj.onsets(j, i):obj.onsets(j,i)+obj.num_bins-1, ...
(j-1)*obj.num_bins+1:(j-1)*obj.num_bins+obj.num_bins)|...
eye(obj.num_bins);
end
end
[~, name, ~] = fileparts(run_id);
obj.path = [dir filesep 'G_' name];
save(obj.path, 'G');
end
function normalize(obj)
load(obj.path);
G = zscore(G, 1);
save(obj.path, 'G')
end
function G = get(obj)
load(obj.path)
end
end
end