rm_chan() - Removes one or more channels (e.g., 'HEOG') from an EEGLAB EEG variable. Unlike EEGLAB functions for removing channels, rm_chan.m is aware of MATLABmk fields (e.g., those pertaining to cal pulse information) and it will adjust them for the deleted channel(s). Usage: >> EEG=rm_chan(EEG,chan_name,force); Required Inputs: EEG - EEGLAB EEG struct variable chan_name - [string or cell array of strings] Name(s) of channel(s) to be removed (e.g., 'HEOG' or {'HEOG','lle','rle'}) Optional Input: force - [0 or 1] If 1, any information pertaining to ICA will be automatically removed from the EEG variable. If 0, the user will first be asked if she/he wants to erase ICA information (if ICA has been performed on this EEG variable). {default: 0} Output: EEG - Same as the input EEG variable but with information for requested channels removed. Example: >>EEG=rm_chan(EEG,'HEOG'); Author: David Groppe Kutaslab, 7/2010
0001 % rm_chan() - Removes one or more channels (e.g., 'HEOG') from an EEGLAB 0002 % EEG variable. Unlike EEGLAB functions for removing channels, 0003 % rm_chan.m is aware of MATLABmk fields (e.g., those pertaining 0004 % to cal pulse information) and it will adjust them for the 0005 % deleted channel(s). 0006 % 0007 % Usage: 0008 % >> EEG=rm_chan(EEG,chan_name,force); 0009 % 0010 % Required Inputs: 0011 % EEG - EEGLAB EEG struct variable 0012 % chan_name - [string or cell array of strings] Name(s) of channel(s) to 0013 % be removed (e.g., 'HEOG' or {'HEOG','lle','rle'}) 0014 % 0015 % Optional Input: 0016 % force - [0 or 1] If 1, any information pertaining to ICA will be 0017 % automatically removed from the EEG variable. If 0, the 0018 % user will first be asked if she/he wants to erase ICA 0019 % information (if ICA has been performed on this EEG variable). 0020 % {default: 0} 0021 % 0022 % Output: 0023 % EEG - Same as the input EEG variable but with information for 0024 % requested channels removed. 0025 % 0026 % Example: 0027 % >>EEG=rm_chan(EEG,'HEOG'); 0028 % 0029 % Author: 0030 % David Groppe 0031 % Kutaslab, 7/2010 0032 0033 function EEG=rm_chan(EEG,chan_name,force) 0034 0035 if ~iscell(chan_name), 0036 chan_names{1}=chan_name; 0037 elseif ischar(chan_name) 0038 chan_names=chan_name; 0039 else 0040 error('Argument chan_name needs to be a string or cell array of strings.'); 0041 end 0042 0043 if nargin<3. 0044 force=0; 0045 end 0046 0047 fldnms=fieldnames(EEG); 0048 0049 %Ask about ICA overwrite 0050 if ~isempty(EEG.icawinv) && ~force, 0051 fprintf('** Warning **\n'); 0052 fprintf('The ICA decomposition stored in this EEG variable will be erased if you proceed.\n'); 0053 fprintf('The decomposition will no longer be valid since you are removing one or more channels.\n'); 0054 resp=input('Do you want to proceed (Y or N)? ','s'); 0055 if strcmpi(resp,'n') || strcmpi(resp,'N'), 0056 fprintf('Call rm_chan.m aborted. EEG variable not modified.\n'); 0057 return 0058 end 0059 end 0060 0061 n_rmv=length(chan_names); 0062 rmv_ids=zeros(1,n_rmv); 0063 for r=1:n_rmv, 0064 n_chan=EEG.nbchan; 0065 %find channel ID# 0066 for c=1:n_chan, 0067 if strcmpi(EEG.chanlocs(c).labels,chan_names{r}), 0068 rmv_ids(r)=c; 0069 end 0070 end 0071 if ~rmv_ids(r), 0072 error('Could not find a channel with the name %s in this EEG variable.',chan_names{r}); 0073 end 0074 end 0075 use_chans=setdiff(1:n_chan,rmv_ids); 0076 0077 %remove channel from data & chanlocs 0078 EEG.data=EEG.data(use_chans,:,:); 0079 EEG.chanlocs=EEG.chanlocs(use_chans); 0080 EEG.nbchan=EEG.nbchan-n_rmv; 0081 0082 %remove channel from calpulse info (MATLABmk fields) 0083 if ismember('cal_info',fldnms), 0084 EEG.cal_info.erps=EEG.cal_info.erps(use_chans,:); 0085 EEG.cal_info.usedcal_itemnum=EEG.cal_info.usedcal_itemnum(use_chans,:); 0086 end 0087 0088 %get rid of EEGLAB ICA info 0089 EEG.icaact=[]; 0090 EEG.icawinv=[]; 0091 EEG.icasphere=[]; 0092 EEG.icaweights=[]; 0093 EEG.icachansind=[]; 0094 EEG.chaninfo.icachansind=[]; 0095 0096 %get rid of MATLABmk ICA info 0097 if ismember('icfeatures',fldnms), 0098 EEG.icfeatures=[]; 0099 EEG.icfreqs=[]; 0100 EEG.iclabels=[]; 0101 EEG.icspectra=[]; 0102 end