% checkcorr - Identify and remove points with bad correlation % % [xclean,Qa]=checkcorr(x,corr,settings); % % Inputs % x = the dirty data set % settings = the fine controls % settings.locorr = 65; % low correlation cutoff % settings.rvalue = NaN; % replacement value to use, default is NaN % % xclean = the fixed data set % Qa = the feedback on what happened % Qa.nbad = the number of bad points % Qa.delmean = the ratio of the means before and after points were replaced % Qa.delvar = the ratio of the variance before and after points were replaced % Qa.stdr = standard deviation of the residuals % % written by Rachel Horwitz % rewritten for a single vector by Marinna Martini function [xclean,Qa] = checkcorr(x,corr,settings); % check inputs if exist('settings', 'var'), if isfield(settings,'locorr'), locorr = settings.locorr; end if isfield(settings, 'rvalue'), rvalue = settings.rvalue; end end if exist('locorr')~=1, locorr = 65; end if exist('rvalue')~=1, rvalue = NaN; end Qa = []; % make sure the shape is consistent [r, c] = size(x); if r == 1, x = x'; end xclean = x; spikes = find(corr < locorr); if ~ischar(rvalue), xclean(spikes) = ones(size(spikes)).*rvalue; elseif strcmp(rvalue, 'median'), xclean(spikes) = ones(size(spikes)).*gmedian(x); else xclean(spikes) = ones(size(spikes)).*gmean(x); end Qa.nbad = length(spikes);