Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)
y = lin_remove_NaN(x,xtim,show)
lin_remove_NaN: linearly remove a time series from data 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. Y = lin_remove(Xdat) assumes Xtim is evenly spaced, so the linear trend is removed.
| This function calls | |
|---|---|
function y = lin_remove_NaN(x,xtim,show)
sz = size(x); ndim = length(sz);
if (ndim == 2) & (sz(1) == 1); x = x(:); end;
sz = size(x); ndim = length(sz);
if nargin < 2; xtim = [1:sz(1)]/sz(1); end;
if nargin < 3; show = 0; end;
if (size(xtim, 1))==1; xtim=xtim(:); end;
if size(xtim, 1)~=sz(1);
error('Xtim must have the same length as the first dimension of Xdat');
end
% Reshape x if necessary, assuming the dimension to be
% detrended is the first
if ndim > 2;
x = reshape(x, sz(1), prod(sz(2:ndim)));
end
% Remove means from data and time series
N = size(x, 1);
xtim = xtim - ones(N, 1)*mean2(xtim);
x = x - ones(N, 1)*mean2(x);
% Remove Regression
[N, m] = size(x);
[NN, mm] = size(xtim);
y = repmat(NaN, [N m]);
for i = 1:m;
if show;
disp(['Iteration: ' num2str(i)]);
end
kp = find(~isnan(x(:,i)));
for j = 1:mm
kp = intersect(kp, find(~isnan(xtim(:, j))));
end
y(kp,i) = x(kp,i) - xtim(kp,:)*(xtim(kp,:)\x(kp,i));
end
% Reshape output so it is the same dimension as input
if ndim > 2;
y = reshape(y, sz);
end