-
Notifications
You must be signed in to change notification settings - Fork 0
/
addIndexArrays.m
81 lines (67 loc) · 2.54 KB
/
addIndexArrays.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
function [newT, oldT] = addIndexArrays(T, condition)
oldT = T(:,:);
CUTOFFSEC = 20;
R = length(T.trials);
for rowNr=1:R
sz = length(T.trials{rowNr});
T.nanFilled{rowNr} = nan(sz,24);
T.seqLen{rowNr} = nan(sz,1);
for j = 1:sz
seqlen = length(T.trials{rowNr}{j,:});
T.seqLen{rowNr}(j)= seqlen;
if seqlen > 24
seqlen = 24;
end
bout = T.trials{rowNr}{j};
T.nanFilled{rowNr}(j,1:seqlen) = ...
T.trials{rowNr}{j}(1,1:seqlen);
end
T.seqDur{rowNr} = max(T.nanFilled{rowNr},[],2) - T.nanFilled{rowNr}(:,1);
T.IPIall{rowNr} = diff(T.nanFilled{rowNr},1,2);
T.normAll{rowNr} = T.nanFilled{rowNr}(:,:)-T.nanFilled{rowNr}(:,1);
% interval between the last press and proceding head check
pLast = max(T.nanFilled{rowNr},[],2);
headEntries = nan(sz,1);
for h = 1:sz
ix = find(T.headEntries{rowNr} > pLast(h), 1);
if isempty(ix)
continue;
else
headEntries(h) = T.headEntries{rowNr}(ix);
end
end
T.magCheckDur{rowNr} = headEntries - pLast;
T.R{rowNr} = ismember(T.nanFilled{rowNr}(:,T.seqLength(rowNr)),T.rewards{rowNr});
if strcmp(condition, 'll')
T.L{rowNr} = ismember(T.nanFilled{rowNr}(:,1),T.laserOn{rowNr});
T.NL{rowNr} = ~T.L{rowNr};
elseif strcmp(condition, 'roi')
% make the logicals to index cases
T.E{rowNr} = false(sz,1); % all ROI crosses
T.L{rowNr} = false(sz,1);
T.entries{rowNr} = false(sz,1);
p1 = T.nanFilled{rowNr}(:,1);
for j = 1:length(T.roiEntries{rowNr})
ix = find(p1 > T.roiEntries{rowNr}(j), 1);
T.entries{rowNr}(ix) = T.roiEntries{rowNr}(j);
if isempty(ix); break; end
T.E{rowNr}(ix) = true;
if ismember(T.roiEntries{rowNr}(j), T.laserOn{rowNr})
T.L{rowNr}(ix) = true;
end
end
T.NL{rowNr} = logical(T.E{rowNr}-T.L{rowNr});
end
T.notTrial{rowNr} = T.normAll{rowNr}(:,2) >= CUTOFFSEC | ...
isnan(T.normAll{rowNr}(:,2)) ...
| isnan(T.normAll{rowNr}(:,3)) | T.seqLen{rowNr} < 3;
end
if strcmp(condition, 'roi')
% concatenate entries and nanfilled arrays
% FOR RASTER PLOTS
T.catEntries = cellfun(@horzcat,T.entries,T.nanFilled,'UniformOutput',false);
% this has all trials including those that were not started with an entry
T.normCatEntries = cellfun(@(x) x-x(:,1), T.catEntries,'UniformOutput', false);
end
newT = T(:,:);
end