Documentation of regress_out


Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)


Function Synopsis

y = detrend(x,time)

Help text

DETREND Linearly remove time series from data.

   Y = DETREND(X,TIME) removes the best linear fit of the time
   series in TIME (possibly multiple) to the data in vector X, and
   returns the result in vector Y.  


Listing of function regress_out

function y = detrend(x,time)

if nargin < 2, error('Must input data and a time series (possibly multiple)'), end

%  Reshape x if necessary, assuming the dimension to be 
%  detrended is the first

szx = size(x); ndimx = length(szx);
if ndimx > 2;
  x = reshape(x, szx(1), prod(szx(2:ndimx)));
end
 
n = size(x,1);
if n == 1,
  x = x(:);			% If a row, turn into column vector
end
N = size(x,1);

if N ~= size(time, 1);
  error('X and TIME must have the same column dimension');
end

  y = x - time*(time\x);		% Remove best fit

if n == 1
  y = y.';
end

%  Reshape output so it is the same dimension as input

if ndimx > 2;
  y = reshape(y, szx);
end