-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plot_Ensemble_Structure.m
85 lines (73 loc) · 1.97 KB
/
Plot_Ensemble_Structure.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
85
function colors_structure = Plot_Ensemble_Structure(structure,colors,new_figure,node_size)
% Plot the structure of the ensembles, i.e., the neurons that belong to the
% ensembles and their weights
%
% colors_structure = Plot_Ensemble_Structure(structure,colors,newfigure,size)
%
% default: colors = []; new_figure = false; node_size = 30
%
% structure: columns represent neurons and rows represent ensembles.
%
% By Jesus Perez-Ortega, Aug 2021
% Modified Sep 2021
% Modified Oct 2021
% Modified Jan 2022 (name changed)
switch nargin
case 1
colors = [];
new_figure = false;
node_size = 30;
case 2
new_figure = false;
node_size = 30;
case 3
node_size = 30;
end
% Set colors
structure = structure';
[n_neurons,n_ensembles] = size(structure);
% Get colors
if isempty(colors)
colors = Read_Colors(n_ensembles);
end
% Get hue
hsvColors = rgb2hsv(colors);
hue = hsvColors(:,1);
hues = repmat(hue,1,n_neurons)';
% Set saturation to colors
for i = 1:n_ensembles
sat = hsvColors(i,2);
saturation(:,i) = structure(:,i)*sat;
end
% Set values
value = hsvColors(:,3);
values = repmat((1-value),1,n_neurons)'.*(1-structure)+repmat(value,1,n_neurons)';
% Create image
color_neurons = hsv2rgb(cat(3,hues,saturation,values));
% Plot structure
if new_figure
Set_Figure('Structure weigthed',[0 0 40*n_ensembles 300]);
end
% Plot each neuron
for i = 1:n_ensembles
colors = squeeze(color_neurons(:,i,:));
for j = n_neurons:-1:1
if sum(colors(j,:))<3
% scatter(i,j,node_size,'MarkerEdgeColor',colors(j,:)*2/3,'MarkerFaceColor',colors(j,:),...
% 'MarkerEdgeAlpha',0.5,'MarkerFaceAlpha',0.5); hold on
scatter(i,j,node_size,colors(j,:),'.'); hold on
end
end
end
if n_ensembles==1
xlim([0.5 1.5])
else
xlim([1 n_ensembles])
end
ylim([1 n_neurons])
xlabel('ensemble #')
ylabel('neuron #')
set(gca,'ydir','normal')
if nargout
colors_structure = color_neurons;
end