-
Notifications
You must be signed in to change notification settings - Fork 2
/
fieldcenters_onedirection.m
84 lines (65 loc) · 2.29 KB
/
fieldcenters_onedirection.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
function fieldcent = fieldcenters_onedirection(peaks_time, goodcells, pos, dim, velthreshold)
%good cells are the ones you know have fields
% field ceenters are the highest spiking point, not the geometric center
%rates returns max rate, av rate, min rate
%velthreshold = 12;
pos = smoothpos(pos);
vel = ca_velocity(pos);
goodvel = find(vel(1,:)>=velthreshold);
goodtime = pos(goodvel, 1);
goodpos = pos(goodvel,:);
mintime = vel(2,1);
maxtime = vel(2,end);
numunits = size(peaks_time,1);
maxrate = [];
for k=1:numunits
if length(find(goodcells(:,1)==k))==0
maxrate(1, k) = NaN;
maxrate(2, k) = NaN;
else
goodcelldir = find(goodcells(:,1)==k);
goodcelldir = goodcells(goodcelldir,:);
highspeedspikes = [];
[c indexmin] = (min(abs(peaks_time(k,:)-mintime))); %
[c indexmax] = (min(abs(peaks_time(k,:)-maxtime))); %
currspikes = peaks_time(k,indexmin:indexmax);
for i=1:length(currspikes) %finding if in good vel
[minValue,closestIndex] = min(abs(currspikes(i)-goodtime));
if minValue <= 1/15 %if spike is within 1 second of moving. no idea if good time
highspeedspikes(end+1) = currspikes(i);
end;
end
%gets direction
fwd = [];
bwd = [];
for z = 1:length(highspeedspikes)
[minValue,closestIndex] = min(abs(pos(:,1)-highspeedspikes(z)));
if pos(max(closestIndex-15, 1),2)-pos(min(closestIndex+15,length(pos)),2)>0
fwd(end+1) = highspeedspikes(z);
else
bwd(end+1) = highspeedspikes(z);
end
end
%subplot(ceil(sqrt(numunits)),ceil(sqrt(numunits)), k)
set(0,'DefaultFigureVisible', 'off');
if length(find(goodcelldir==1))>0
goodpos(:,3) = 1;
[rate totspikes totstime colorbar spikeprob occprob] = normalizePosData(fwd,goodpos,dim, 2.5);
rate = smoothdata(rate, 'gaussian', dim);
[maxval,maxindex] = max(rate);
maxrate(1, k) = maxindex;
else
maxrate(1, k) = NaN;
end
if length(find(goodcelldir==2))>0
goodpos(:,3) = 1;
[rate totspikes totstime colorbar spikeprob occprob] = normalizePosData(bwd,goodpos,dim, 2.5);
rate = smoothdata(rate, 'gaussian', dim);
[maxval,maxindex] = max(rate);
maxrate(2, k) = maxindex;
else
maxrate(2, k) = NaN;
end
end
end
fieldcent = maxrate';