Home > vbmeg > external > mne > fiff_pick_channels.m

fiff_pick_channels

PURPOSE ^

SYNOPSIS ^

function [sel] = fiff_pick_channels(ch_names,include,exclude)

DESCRIPTION ^

 [sel] = fiff_pick_channels(ch_names,include,exclude)

 Make a selector to pick desired channels from data

 ch_names  - The channel name list to consult
 include   - Channels to include (if empty, include all available)
 exclude   - Channels to exclude (if empty, do not exclude any)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [sel] = fiff_pick_channels(ch_names,include,exclude)
0002 %
0003 % [sel] = fiff_pick_channels(ch_names,include,exclude)
0004 %
0005 % Make a selector to pick desired channels from data
0006 %
0007 % ch_names  - The channel name list to consult
0008 % include   - Channels to include (if empty, include all available)
0009 % exclude   - Channels to exclude (if empty, do not exclude any)
0010 %
0011 %
0012 
0013 %
0014 %   Author : Matti Hamalainen, MGH Martinos Center
0015 %   License : BSD 3-clause
0016 %
0017 %
0018 %   Revision 1.5  2008/04/06 16:35:35  msh
0019 %   Added reasonable handling of duplicate channel names.
0020 %
0021 %   Revision 1.4  2006/06/29 22:12:28  msh
0022 %   Fixed errors in channel picking
0023 %
0024 %   Revision 1.3  2006/04/27 22:38:37  msh
0025 %   Splitting an empty list now results in an empty output.
0026 %   Added fiff_write_double and fiff_write_short
0027 %   Write an array of floats, ints, and doubles instead of just one value.
0028 %   Fixed help text of fiff_pick_channels.
0029 %
0030 %   Revision 1.2  2006/04/23 15:29:40  msh
0031 %   Added MGH to the copyright
0032 %
0033 %   Revision 1.1  2006/04/20 23:33:20  msh
0034 %   Separated fiff_pick_channels and fiff_pick_types from the _evoked versions
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     %   Include all initially
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     %  Check for exclusions
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     %   First do the channels to be included
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         %  Is this channel in the exclusion list?
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     %    Check whether some channels were excluded
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

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005