-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlot_Ensembles_Length.m
52 lines (41 loc) · 1.36 KB
/
Plot_Ensembles_Length.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
function widths = Plot_Ensembles_Length(indices,sequence,name,fps)
% Identify the legnth of the ensembles and plot the distribution of each one
%
% widths = Plot_Ensembles_Length(indices,sequence,name,fps)
%
% By Jesus Perez-Ortega, Feb 2020
% Find vectors
id = find(indices>0);
% Get the ensemble id
ensembles = unique(sequence)';
nEns = length(ensembles);
% Get colors
colors = Read_Colors(max(ensembles));
Set_Figure(['Ensemble length - ' name],[0 0 1200 200])
maxH = 0;
for i = 1:nEns
seqEns = [];
% Create binary signal to identify the lenght of each activation
seqEns(id(sequence==ensembles(i))) = 1;
[~,w] = Find_Peaks_Or_Valleys(seqEns);
nPeaks = length(w);
% Plot histogram
subplot(1,max(ensembles),ensembles(i))
h = histogram(w,'BinWidth',1,'FaceColor',colors(ensembles(i),:));
y = h.Values;
maxH = max([maxH h.BinLimits(2)]);
% Display the average width
title([num2str(nPeaks) ' (' num2str(mean(w)/fps,'%.2f') '±' num2str(std(w)/fps,'%.2f') ' s)'])
widths{ensembles(i)} = w;
if i==1
ylabel({'Count of';'ensemble activations'})
end
end
% Set same maximum x limit
for i = ensembles
subplot(1,max(ensembles),i)
Set_Label_Time(maxH,fps)
xlim([0 maxH])
label = get(gca,'xlabel');
xlabel(['Length ' label.String])
end