-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprt_plot_2D_weights.m
More file actions
102 lines (84 loc) · 2.64 KB
/
Copy pathprt_plot_2D_weights.m
File metadata and controls
102 lines (84 loc) · 2.64 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function [h] = prt_plot_2D_weights(parent,weights,weights_D)
% Function to plot 2D weights from .mat or MEEG modalities
% Inputs: Parent graph handle and weights, the 2D matrix of values
% Output: Handle to obtained plot
%__________________________________________________________________________
% Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
% Written by J. Schrouff
% $Id$
% Remove figure axes and plots
gch = get(parent,'Children');
for i=1:numel(gch)
if strcmp(gch(i).Tag,'uipanelmat_topoplots')
continue
end
delete(gch(i));
end
% Draw axes (properties depend on Matlab version)
try
axmat = axes(parent,'units','normalized', ...
'position',[0.037 0.17 0.585 0.7], 'NextPlot', 'add');
catch
axmat = axes('units','normalized', 'NextPlot', 'add', ...
'position',[0.037 0.17 0.585 0.7],'parent',parent);
end
% Define colormap
minw = min(min(weights));
minw = min(minw,0);
maxw = max(max(weights));
maxw = max(maxw,0);
if minw<0 && maxw>0 % Both negative and positive, diverging colormap
colneg = cbrewer('seq','Blues',128,'PCHIP');
colpos = cbrewer('seq','Reds',128,'PCHIP');
cols = [flip(colneg,1);colpos];
elseif minw>=0 && maxw>0 % Only positive, sequential red colormap
cols = cbrewer('seq','Reds',256,'PCHIP');
elseif minw<0 && maxw<=0 % Only negative, sequential blue colormap
colneg= cbrewer('seq','Blues',256,'PCHIP');
cols = flip(colneg,1);
elseif minw==0 && maxw==0 % All zeros, just gray
cols = [0.5 0.5 0.5];
elseif isnan(minw) && isnan(maxw)
weights = zeros(size(weights));
cols = [0.5 0.5 0.5];
end
colormap(cols);
try
h = imagesc(axmat,weights);
catch
set(gcf,'CurrentAxes',axmat)
h = imagesc(weights);
end
xlim([1 size(weights,2)])
ylim([1 size(weights,1)])
xaxmat = weights_D.ftraw.time{1,length(weights_D.ftraw.time)};
xaxmat = round(xaxmat,5);
xaxmat = xaxmat';
xaxmat = xaxmat*1000;
zero_ind = find(xaxmat==0);
dummy_var2 = [zero_ind];
while max(dummy_var2) < length(weights_D.time)
i = max(dummy_var2)+20;
dummy_var2 = [dummy_var2 i];
end
xticks(dummy_var2)
dummy_var = ones(1,length(xaxmat));
xaxmat = mat2cell(xaxmat,dummy_var);
xaxmat = xaxmat';
xticklabels(xaxmat(dummy_var2));
try
hc = colorbar(axmat,'Units','normalized','Position',[0.638 0.17 0.02 0.7]);
catch
hc = colorbar('peer',axmat,'Units','normalized','Position',[0.638 0.17 0.02 0.7]);
end
% Change colorbar limits to ensure centered white if positive and negative
if minw<0 && maxw>0
try
limhc = get(hc,'Limits');
limw = max(abs(limhc));
catch
absw = abs(weights);
limw = max(max(absw));
end
caxis(limw * [-1 1]);
end