0001 function [sel] = fiff_pick_channels(ch_names,include,exclude)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 me='MNE:fiff_pick_channels';
0039
0040 nchan = length(ch_names);
0041 if nargin == 1
0042 sel = ones(1,nchan);
0043 for k = 1:nchan
0044 sel(k) = k;
0045 end
0046 return;
0047 elseif nargin == 2
0048 exclude = [];
0049 elseif nargin ~= 3
0050 error(me,'Incorrect number of arguments');
0051 end
0052
0053 if isempty(include)
0054
0055
0056
0057 sel = zeros(1,nchan);
0058 for k = 1:nchan
0059 sel(k) = k;
0060 end
0061 nzero = 0;
0062 for k = 1:length(exclude)
0063 c = strmatch(exclude{k},ch_names,'exact');
0064 if length(c) > 0
0065 sel(c(1)) = 0;
0066 nzero = nzero + 1;
0067 end
0068 end
0069
0070
0071
0072 if nzero > 0
0073 newsel = zeros(1,nchan-nzero);
0074 p = 0;
0075 for k = 1:nchan
0076 if sel(k) > 0
0077 p = p + 1;
0078 newsel(p) = sel(k);
0079 end
0080 end
0081 sel = newsel;
0082 end
0083 else
0084
0085
0086
0087 sel = zeros(1,length(include));
0088 nzero = 0;
0089 for k = 1:length(include)
0090 c = strmatch(include{k},ch_names,'exact');
0091 if ~length(c)
0092 error(me,'Missing channel %s',include{k});
0093 elseif length(c) > 1
0094 disp(sprintf('Ambiguous channel, taking first occurence: %s',include{k}));
0095 end
0096
0097
0098
0099 sel(k) = c(1);
0100 if ~isempty(exclude)
0101 c = strmatch(include{k},exclude,'exact');
0102 if length(c) > 0
0103 sel(k) = 0;
0104 nzero = nzero + 1;
0105 end
0106 end
0107 end
0108
0109
0110
0111 if nzero > 0
0112 newsel = zeros(1,length(include)-nzero);
0113 p = 0;
0114 for k = 1:length(include)
0115 if sel(k) > 0
0116 p = p + 1;
0117 newsel(p) = sel(k);
0118 end
0119 end
0120 sel = newsel;
0121 end
0122 end
0123
0124 return;
0125
0126 end
0127
0128
0129