forked from nigelrogasch/TESA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesa_chansel.m
More file actions
145 lines (136 loc) · 5.26 KB
/
tesa_chansel.m
File metadata and controls
145 lines (136 loc) · 5.26 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
% pop_chansel() - pop up a graphic interface to select channels
%
% Usage:
% >> [chanlist] = pop_chansel(chanstruct); % a window pops up
% >> [chanlist strchannames cellchannames] = ...
% pop_chansel(chanstruct, 'key', 'val', ...);
%
% Inputs:
% chanstruct - channel structure. See readlocs()
%
% Optional input:
% 'withindex' - ['on'|'off'] add index to each entry. May also a be
% an array of indices
% 'select' - selection of channel. Can take as input all the
% outputs of this function.
% 'selectionmode' - selection mode 'multiple' or 'single'. See listdlg2().
%
% Output:
% chanlist - indices of selected channels
% strchannames - names of selected channel names in a concatenated string
% (channel names are separated by space characters)
% cellchannames - names of selected channel names in a cell array
%
% Author: Arnaud Delorme, CNL / Salk Institute, 3 March 2003
% Copyright (C) 3 March 2003 Arnaud Delorme, Salk Institute, arno@salk.edu
%
% 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 [chanlist,chanliststr, allchanstr] = pop_chansel(chans, varargin);
if nargin < 1
help pop_chansel;
return;
end;
if isempty(chans), disp('Empty input'); return; end;
if isnumeric(chans),
for c = 1:length(chans)
newchans{c} = num2str(chans(c));
end;
chans = newchans;
end;
chanlist = [];
chanliststr = {};
allchanstr = '';
g = finputcheck(varargin, { 'withindex' { 'integer';'string' } { [] {'on' 'off'} } 'off';
'select' { 'cell';'string';'integer' } [] [];
'selectionmode' 'string' { 'single';'multiple' } 'multiple'});
if isstr(g), error(g); end;
if ~isstr(g.withindex), chan_indices = g.withindex; g.withindex = 'on';
else chan_indices = 1:length(chans);
end;
% convert selection to integer
% ----------------------------
if isstr(g.select) & ~isempty(g.select)
g.select = parsetxt(g.select);
end;
if iscell(g.select) & ~isempty(g.select)
if isstr(g.select{1})
tmplower = lower( chans );
for index = 1:length(g.select)
matchind = strmatch(lower(g.select{index}), tmplower, 'exact');
if ~isempty(matchind), g.select{index} = matchind;
else error( [ 'Cannot find ''' g.select{index} '''' ] );
end;
end;
end;
g.select = [ g.select{:} ];
end;
if ~isnumeric( g.select ), g.select = []; end;
% add index to channel name
% -------------------------
tmpstr = {chans};
if isnumeric(chans{1})
tmpstr = [ chans{:} ];
tmpfieldnames = cell(1, length(tmpstr));
for index=1:length(tmpstr),
if strcmpi(g.withindex, 'on')
tmpfieldnames{index} = [ num2str(chan_indices(index)) ' - ' num2str(tmpstr(index)) ];
else
tmpfieldnames{index} = num2str(tmpstr(index));
end;
end;
else
tmpfieldnames = chans;
if strcmpi(g.withindex, 'on')
for index=1:length(tmpfieldnames),
tmpfieldnames{index} = [ num2str(chan_indices(index)) ' - ' tmpfieldnames{index} ];
end;
end;
end;
[chanlist,tmp,chanliststr] = listdlg2('PromptString',strvcat('Select a channel', 'to use for', 'peak detection...'), ...
'ListString', tmpfieldnames, 'initialvalue', g.select, 'selectionmode', g.selectionmode);
if tmp == 0
chanlist = [];
chanliststr = '';
return;
else
allchanstr = chans(chanlist);
end;
% test for spaces
% ---------------
spacepresent = 0;
if ~isnumeric(chans{1})
tmpstrs = [ allchanstr{:} ];
if ~isempty( find(tmpstrs == ' ')) | ~isempty( find(tmpstrs == 9))
spacepresent = 1;
end;
end;
% get concatenated string (if index)
% -----------------------
if strcmpi(g.withindex, 'on') | spacepresent
if isnumeric(chans{1})
chanliststr = num2str(celltomat(allchanstr));
else
chanliststr = '';
for index = 1:length(allchanstr)
if spacepresent
chanliststr = [ chanliststr '''' allchanstr{index} ''' ' ];
else
chanliststr = [ chanliststr allchanstr{index} ' ' ];
end;
end;
chanliststr = chanliststr(1:end-1);
end;
end;
return;