function [variable] = exclude(varargin) %(varargin) = (var,list,dim) %excludes those values of 'var' that correspond to indices listed in the vector 'list.' %for example, if 'list' lists the outliers that were excluded from the data, this function %will exclude those same epochs from the variable vector. %dim is the dimension for exclusion (assumed to be 1 if not specified). %works for array of up to 3 dimensions. var = varargin{1}; list = varargin{2}; if (length(varargin))>=3 dim = varargin{3}; else dim = 1; end list1 = sort(list,'descend'); if ((ndims(var)==1) || (ndims(var)==2)) if dim==1 variable = var; elseif dim==2 variable = var'; end for i = 1:length(list(:,1)) variable(list1(i,1),:) = []; end if dim==2 variable = variable'; end elseif ndims(var)==3 variable = var; if dim==2 variable = permute(variable,[2,1,3]); elseif dim==3 variable = permute(variable,[3,2,1]); end for i = 1:length(list(:,1)) variable(list1(i,1),:,:) = []; end if dim==2 variable = permute(variable,[2,1,3]); elseif dim==3 variable = permute(variable,[3,2,1]); end end end