-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jitter_Raster.m
42 lines (32 loc) · 913 Bytes
/
Jitter_Raster.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
% Jitter a raster with an specific bin
%
% Jes?s P?rez-Ortega - Sep 2018
function jittered = Jitter_Raster(raster,bin,exact_bin)
if(nargin==2)
exact_bin=false;
end
[n_cells,n_samples]=size(raster);
jittered=zeros(n_cells,n_samples);
for i=1:n_cells
cell=raster(i,:);
t=find(cell);
jit=rand(1,length(t));
if(exact_bin)
jit(jit>0.5)=bin;
jit(jit<=0.5)=-bin;
else
jit=round(jit*2*bin)-bin;
end
t_jit=t+jit;
t_jit=sort(t_jit);
if(max(t_jit)>n_samples)
n_extra=length(find(t_jit>n_samples));
t_jit=t_jit(1:end-n_extra);
end
if(min(t_jit)<1)
n_extra=length(find(t_jit<1));
t_jit=t_jit(1+n_extra:end);
end
jittered(i,t_jit)=1;
end
end