[422372]: / functions / popfunc / pop_chansel.m

Download this file

173 lines (162 with data), 6.7 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
% 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.
% 'field' - ['type'|'labels'] information to select. Default is
% 'labels'
% 'handle' - [handle] update handle (GUI)
% '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 file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.
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' '' [] 'off';
'select' '' [] [];
'handle' '' [] [];
'field' 'string' [] 'labels';
'selectionmode' 'string' { 'single';'multiple' } 'multiple'});
if ischar(g), error(g); end
if ~ischar(g.withindex), chan_indices = g.withindex; g.withindex = 'on';
else chan_indices = 1:length(chans);
end
if isstruct(chans), chans = { chans.(g.field) }; end
if strcmpi(g.field, 'type'), chans = unique_bc(chans); end
% convert selection to integer
% ----------------------------
if ischar(g.select) && ~isempty(g.select)
g.select = parsetxt(g.select);
end
if iscell(g.select) && ~isempty(g.select)
if ischar(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
if strcmpi( g.selectionmode, 'single')
[chanlist,tmp,chanliststr] = listdlg2('PromptString', 'Select channel below', ...
'ListString', tmpfieldnames, 'initialvalue', g.select, 'selectionmode', g.selectionmode);
else
[chanlist,tmp,chanliststr] = listdlg2('PromptString',strvcat('(use shift|Ctrl to', 'select several)'), ...
'ListString', tmpfieldnames, 'initialvalue', g.select, 'selectionmode', g.selectionmode);
end
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
if ~isempty(g.handle)
set(g.handle, 'string', chanliststr);
end
return;