-
Notifications
You must be signed in to change notification settings - Fork 1
/
pop_eeglab2loreta.m
112 lines (103 loc) · 4.99 KB
/
pop_eeglab2loreta.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
% pop_eeglab2loreta() - export EEGLAB data and channel locations to LORETA
%
% Usage:
% >> pop_eeglab2loreta( EEG, 'key', 'val' );
%
% Inputs:
% EEG - EEGLAB dataset structure
%
% Optional inputs:
% 'excludechans' - indices of channels to exclude
% 'labelonly' - only export channel labels (which position can be
% be then looked up in LORETA)
% 'compnum' - indices of components.
%
% Author: Arnaud Delorme, CNL / Salk Institute, 2005
%
% See also: eeglab2loreta()
% Copyright (C) 2005 Arnaud Delorme, Salk Institute, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function command = pop_eeglab2loreta(EEG, varargin);
command = '';
if nargin < 1
help pop_eeglab2loreta;
return;
end;
if nargin > 2
eeglab2loreta(EEG.chanlocs, EEG.icawinv, varargin{:});
return;
end;
commandload = [ 'filepath = uigetdir(pwd, ''Select a folder'');' ...
'if filepath ~=0,' ...
' set(findobj(''parent'', gcbf, ''tag'', ''folder''), ''string'', filepath);' ...
'end;' ...
'clear filepath;' ];
cb_plotcomps = [ 'compinds = str2num(get(findobj(gcbf, ''tag'', ''compind''), ''string''));' ...
'if length(compinds) == 1, figure; end; pop_topoplot(EEG, 0, compinds);' ];
cb_erp = 'set(findobj(gcbf, ''tag'', ''compind''), ''enable'', fastif(isempty(get(gcbo, ''string'')), ''on'', ''off''));';
listui = { { 'style' 'text' 'string' 'Ouput folder (default current folder)' } ...
{ 'style' 'edit' 'string' '' 'tag' 'folder' } ...
{ 'style' 'pushbutton' 'string' 'Browse' 'callback' commandload } ...
{ 'style' 'text' 'string' 'Export channel labels only' } ...
{ 'style' 'checkbox' 'string' '' 'value' 1 } ...
{ 'style' 'text' 'string' '(check=yes)' } ...
{ 'style' 'text' 'string' 'Omit channel indices' } ...
{ 'style' 'edit' 'string' '' } ...
{ } ...
{ 'style' 'text' 'string' 'Export ICA component indices' } ...
{ 'style' 'edit' 'string' [ '1:' num2str(size(EEG.icawinv,2)) ] 'tag', 'compind' } ...
{ 'style' 'pushbutton' 'string' 'Plot topo.' 'callback' cb_plotcomps } ...
{ 'style' 'text' 'string' 'ICA comp. polarity inversion (1 -1 ...)' } ...
{ 'style' 'edit' 'string' '' 'tag', 'polinv' } {} ...
{ 'style' 'text' 'string' 'or export ERP time range [min max] (ms)' } ...
{ 'style' 'edit' 'string' '' 'tag', 'erp' 'callback' cb_erp } ...
{ } ...
};
geom = { [1 0.5 0.5] [1 0.5 0.5] [1 0.5 0.5] [1 0.5 0.5] [1 0.5 0.5] [1 0.5 0.5] };
results = inputgui('geometry', geom, 'uilist', listui, 'helpcom', 'pophelp(''pop_eeglab2loreta'')', ...
'title', 'Export EEG info to LORETA');
if isempty(results), return; end;
% decode inputs
% -------------
folderout = results{1};
if isempty(folderout), disp('Saving files to current folder'); end;
options = {};
if results{2}
options = { 'labelonly' 'on' };
end
if ~isempty(results{3})
options = { options{:} 'excludechan' eval( [ '[' results{3} ']' ] ) };
end
% export erp
% ----------
if ~isempty(results{6})
timerange = eval( [ '[' results{6} ']' ] );
[tmp minind1] = min(abs(EEG.times-timerange(1)));
[tmp minind2] = min(abs(EEG.times-timerange(2)));
eeglab2loreta(EEG.chanlocs, mean(EEG.data(:, minind1:minind2, :), 3), 'exporterp', 'on', options{:});
return;
end;
% export comps
% ------------
if ~isempty(results{4})
compnums = eval( [ '[' results{4} ']' ] );
end
if ~isempty(results{5})
options = { options{:} 'polinv' eval( [ '[' results{5} ']' ] ) };
end
eeglab2loreta(EEG.chanlocs, EEG.icawinv, 'compnum', compnums, options{:});
warndlg2( [ 'See https://sccn.ucsd.edu/wiki/LORETA_for_EEGLAB for further instructions' 10 '(hyperlink available on the Matlab command line)' ] );
fprintf('See <a href="https://sccn.ucsd.edu/wiki/LORETA_for_EEGLAB">https://sccn.ucsd.edu/wiki/LORETA_for_EEGLAB</a> for further instructions\n');