% rm_badsamp - Replace bad samples in a burst (ie:replace 1st 5 pressures) % replaces fixbadsenors- operates on any sensor specified % % [xclean,Qa]=rm_badsamp(x,settings); % % called from cleanhydra for each burst % Inputs % x = the dirty data set, a structure defined as % settings = the fine controls % settings.samps = samples to replace % settings.rvalue = 1e35; % replacement value to use instead of NaN (default) % % can be 'mean', 'median' or a value % % xclean = the fixed data set % Qa = the feedback on what happened % Qa.idx_rem = index numbers of the samples replaced % Qa.n_rem == number of samples replaced % written by Ellyn Montgomery function [xclean,Qa] = rd_badsamp(x,settings) % % usage seta.samps=[1:5 end-10:end]; seta.rvalue=1e35; % [xclean,Qa] = rd_badsamp(x,seta) % check inputs if exist('settings', 'var'), if isfield(settings,'samps'), samp_ng = settings.samps; end if isfield(settings, 'rvalue'), rvalue = settings.rvalue; end end if exist('rvalue','var')~=1, rvalue = NaN; end warning off MATLAB:divideByZero; % make sure the shape is consistent nrows = size(x, 1); if nrows == 1, x = x'; end xclean = x; if ~ischar(rvalue), ngfill=ones(length(samp_ng),1)*rvalue; % make a fill array elseif strcmp(rvalue,'median') ngfill=ones(length(samp_ng),1)*gmedian(setxor(x,x(samp_ng))); else % use the mean ngfill=ones(size(samp_ng))*gmean(setxor(x,x(samp_ng))); end xclean(samp_ng)=ngfill; % replace the specified samples Qa.n_rep = length(samp_ng); Qa.idx_rep = samp_ng;