Global Index (short | long) | Local contents | Local Index (short | long)
y = lin_remove_NaN(xdat, xtim, tol, show);
function Y = lin_remove_NaN ( Xdat , Xtim , tol , show ) ; Y = lin_remove(Xdat, Xtim) removes the best linear fit of Xtim to each column of Xdat. If Xdat is N-dimensional, then it is assumed that the time series Xtim will be removed from the first dimension of Xdat. This function ignores elements of Xdat and Xtim that have NaNs. tol is the number of common points required between xdat(:,i) and _every_ column of xtim, in order for xtim to be removed from xdat. So, y will only have (max) as many rows as the least amount of data in any column of xtim. show = 'show', 'noshow', or 1, 0, respectively. This routine is quicker than lin_remove_NaN_defunct, and seems to do the same thing.
function y = lin_remove_NaN(xdat, xtim, tol, show); sz = size(xdat); ndim = length(sz); if (ndim == 2) & (sz(1) == 1); xdat = xdat(:); end; sz = size(xdat); ndim = length(sz); if nargin < 3; tol = 2; end; if nargin < 4; show = 0; end; if isstr(show); show = strcmp(show, 'show'); end if (size(xdat, 1) ~= size(xtim, 1)); error('The number of columns of xdat and xtim must be equal'); end [m1, n1] = size(xdat); [m2, n2] = size(xtim); % Condense data to get rid of NaN's in Xtim if n2 > 1; kp_time = find(~isnan(sum(xtim'))); else kp_time = find(~isnan(xtim)); end nkp_time = length(kp_time); xdat = xdat(kp_time,:); xtim = xtim(kp_time,:); % Start regressions and removals if show; disp(['Number of iterations: ' num2str(n1)]); end; c = repmat(NaN, [nkp_time, n1]); for i = 1:n1; if show; disp(['Iteration ' num2str(i) ' of ' num2str(n1)]); end; if n2 > 1; kp = find(sum( ~isnan((xdat(:,i)*ones(1,n2)) .* xtim)') == n2 ); else kp = find(~isnan(xdat(:,i) .* xtim)); end nkp = length(kp); if nkp > tol c(kp,i) = xdat(kp,i) - xtim(kp,:)*(xtim(kp,:)\xdat(kp,i)); end end % Reshape output so it is the same dimension as input y = repmat(NaN, [m1, n1]); y(kp_time,:) = c; if ndim > 2; y = reshape(y, sz); end