-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_brainNetworks_fraction.m
executable file
·79 lines (71 loc) · 2.81 KB
/
draw_brainNetworks_fraction.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
function ax = draw_brainNetworks_fraction(ax, connectome, nodeLocations, ...
frac, markersize, node_data, node_cmap, ...
edge_color, edge_width, slice)
% draw_brainNetworks_fraction.m
%
% Draw a scatter plot of brain network showing a fraction of top connections
%
% Inputs: ax : axis handle to plot on
% connectome : weighted connectivity matrix [NxN]
% nodeLocations : 3D locations of the nodes [Nx3]
% frac : fraction of top weights to show in (float)
% 0 = no weights preserved
% 1 = all weights preserved
% markersize : uniform size of the nodes (float)
% node_data : node_data [Mx3]
% node_cmap : colormap of node_data [Mx3]
% edge_color : color of edges (string) or [1x3]
% edge_width : linewidth of edge [float]
% slice : view slice (string)
% 'axial', 'sagittal_left', 'sagittal_right',
% 'coronal'
% Outputs: ax : redefine initial axis handle
%
% Original: James Pang, QIMR Berghofer, 2020
%%
if nargin < 10
slice = 'axial';
end
if nargin<9
edge_width = 1;
end
if nargin<8
edge_color = [0 0.5 0 0.1];
end
if nargin<7
node_cmap = [1,0,0];
end
if nargin<6
node_data = ones(size(connectome,2),1);
end
if nargin<5
markersize = 30;
end
if nargin<4
frac = 0.1;
end
connectome_thres = threshold_proportional(connectome, frac); % threshold connectome
[edge_X, edge_Y, edge_Z] = adjacency_plot_und(connectome_thres, nodeLocations); % get all the edges
if strcmpi(slice, 'axial')
nodeLocations = cat(2, nodeLocations(:,1), nodeLocations(:,2), nodeLocations(:,3));
edges = cat(2, edge_X, edge_Y, edge_Z);
elseif strcmpi(slice, 'sagittal_left')
nodeLocations = cat(2, -nodeLocations(:,2), nodeLocations(:,3), -nodeLocations(:,1));
edges = cat(2, -edge_Y, edge_Z, -edge_X);
elseif strcmpi(slice, 'sagittal_right')
nodeLocations = cat(2, nodeLocations(:,2), nodeLocations(:,3), nodeLocations(:,1));
edges = cat(2, edge_Y, edge_Z, edge_X);
elseif strcmpi(slice, 'coronal')
nodeLocations = cat(2, nodeLocations(:,1), nodeLocations(:,3), -nodeLocations(:,2));
edges = cat(2, edge_X, edge_Z, -edge_Y);
end
hold on;
plot3(edges(:,1), edges(:,2), edges(:,3), 'color', edge_color, 'linewidth', edge_width);
scatter3(ax, nodeLocations(:,1), nodeLocations(:,2), nodeLocations(:,3), ...
markersize, node_data, 'filled', 'markeredgecolor', 'k');
hold off;
set(ax, 'colormap', node_cmap)
view(ax, 2)
axis(ax, 'equal')
set(ax, 'visible', 'off')
end