-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport_ZNormSweeps.m
37 lines (31 loc) · 1.49 KB
/
support_ZNormSweeps.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
function NewTrialsArray = support_ZNormSweeps(Samples, TrialsArray, SearchBaseMask, Z_norm_method)
NewTrialsArray = NaN(size(TrialsArray));
if Z_norm_method == 1
log_i('Using Z-normalization referenced to whole recording');
elseif Z_norm_method == 2
log_i('Using Z-normalization referenced to all each trial on its own');
elseif Z_norm_method == 3
log_i('Using Z-normalization referenced to all existing trials');
elseif Z_norm_method == 4
log_i('Using Z-normalization referenced to all non-rejected trials');
else
log_e('Invalid Z-normalization method defined');
end
for i = 1:size(TrialsArray,2)
if ~SearchBaseMask(i)
continue
end
if Z_norm_method == 1
z_norm_reference = std(Samples.Pupdil, 'omitnan');
elseif Z_norm_method == 2
z_norm_reference = std(TrialsArray(:,i), 'omitnan');
elseif Z_norm_method == 3
z_norm_reference = std(reshape(TrialsArray(:,1:numTrials),1,[]), 'omitnan'); % convert matrix to row vector
elseif Z_norm_method == 4
z_norm_reference = std(reshape(TrialsArray(~RejectedTrials,i),1,[]), 'omitnan'); % convert matrix to row vector
%else
% log_e('Invalid Z-normalization method defined');
end
NewTrialsArray(:,i) = (TrialsArray(:,i) - mean(z_norm_reference, 'omitnan'))./z_norm_reference;
end
end