-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathlimo_edit_expected_chanlocs.m
118 lines (107 loc) · 4.12 KB
/
limo_edit_expected_chanlocs.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
function [expected_chanlocs, channeighbstructmat] = limo_edit_expected_chanlocs(gp_level_file)
% Routine to edit the neighbouring matrix of (expected) chanlocs.
% While this is typically the group level matrix, this works as well for
% single subjects (i.e. loading a LIMO file).
%
% Cyril Pernet
% ------------------------------
% Copyright (C) LIMO Team 2019
%% if no input - ask for it
if nargin == 0
[gp_level_file,filepath,sts]=uigetfile('*.mat','select gp level channel file or LIMO.mat');
if sts ==0
expected_chanlocs = [];
channeighbstructmat = [];
return
end
end
%% load file
if ischar(gp_level_file)
tmp = load([filepath gp_level_file]);
else
LIMO = gp_level_file;
tmp = struct('LIMO',LIMO);
end
if isfield(tmp,'LIMO')
if isfield(tmp.LIMO.data,'channeighbstructmat')
channeighbstructmat = tmp.LIMO.data.channeighbstructmat;
if isfield(tmp.LIMO.data,'chanlocs')
expected_chanlocs = tmp.LIMO.data.chanlocs;
elseif isfield(tmp.LIMO.data,'expected_chanlocs')
expected_chanlocs = tmp.LIMO.data.expected_chanlocs;
end
else
errordg2('This LIMO fle does not have any neighbourging matrix, compute first then edit');
return
end
else % a group level file
if ~isfield(tmp,'expected_chanlocs')
errordlg2('this file does not have any channel location?')
return
elseif ~isfield(tmp,'channeighbstructmat')
errordlg2('this file does not have any neighbouring matrix?')
return
else
expected_chanlocs = tmp.expected_chanlocs;
channeighbstructmat = tmp.channeighbstructmat;
clear tmp
end
end
%% show and edit
figure('Name','Channel locations')
topoplot([], expected_chanlocs,'style','blank','electrodes','labelpoint','chaninfo',expected_chanlocs);
figure('Name','Neighbouring matrix')
imagesc(channeighbstructmat); colormap(gray);
for i=length(expected_chanlocs):-1:1
if isfield(expected_chanlocs,'urchan')
label{i}= expected_chanlocs(i).urchan;
else
label{i}= expected_chanlocs(i).labels;
end
end
set(gca,'YTick',1:3:length(expected_chanlocs),'YTickLabel', label(1:3:length(expected_chanlocs)))
set(gca,'XTick',2:3:length(expected_chanlocs),'XTickLabel', label(2:3:length(expected_chanlocs)))
axis([1 length(expected_chanlocs) 1 length(expected_chanlocs)]); axis square
title(sprintf('Connectivity matrix between channels \n (click outside the matrix or right click when done)'),'FontSize',14)
cmap = gray; cmap(1,:) = [0.25 0.25 0.25]; colormap(cmap)
% interactive editing
positive = 1;
while positive == 1
try
[x, y, button]=ginput(1);
catch ginputaborded
fprintf('Neighbouring %s\n',ginputaborded.message);
expected_chanlocs = [];
channeighbstructmat = [];
return
end
if any([x y]< 0) || any([x y]> length(channeighbstructmat)) || button ~= 1
positive = 0;
else
if channeighbstructmat(round(x),round(y)) == 0
channeighbstructmat(round(x),round(y)) = 1;
channeighbstructmat(round(y),round(x)) = 1;
imagesc(channeighbstructmat); v = 'on';
else
channeighbstructmat(round(x),round(y)) = 0;
channeighbstructmat(round(y),round(x)) = 0;
imagesc(channeighbstructmat); v = 'off';
end
colormap(cmap);
set(gca,'YTick',[1:3:length(expected_chanlocs)],'YTickLabel', label(1:3:length(expected_chanlocs)))
set(gca,'XTick',[2:3:length(expected_chanlocs)],'XTickLabel', label(2:3:length(expected_chanlocs)))
axis([1 length(expected_chanlocs) 1 length(expected_chanlocs)]); axis square
title(sprintf('Connectivity matrix between channels \nconnection %g %g %s',round(x),round(y),v),'FontSize',14)
end
end
%% check where to save
if nargout == 0
if isfield(tmp,'LIMO')
LIMO = tmp.LIMO;
LIMO.data.channeighbstructmat = channeighbstructmat;
save(fullfile(LIMO.dir,'LIMO.mat'),'LIMO');
disp('LIMO file neighbouring matrix saved')
else
uisave('expected_chanlocs','channeighbstructmat') % save all in one file
end
end