This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Subtract mean or best-fit line from timeseries object


tsout = detrend(tsin,method)
tsout = detrend(tsin,method,ind)



tsout = detrend(tsin,method) subtracts either a mean or a best-fit line from 2-D data in a timeseries using the specified method, and also removes all NaN values.


tsout = detrend(tsin,method,ind) specifies the indices of the columns or rows to detrend. ind is a vector of integers representing column indices for column-oriented data (tsin.IsTimeFirst is true) and representing row indices for row-oriented data (tsin.IsTimeFirst is false).


collapse all

Create a timeseries object with 2-D data, and subtract the mean of each column from the data.

A = magic(3)
A = 3×3

     8     1     6
     3     5     7
     4     9     2

tsin = timeseries(A,[1 2 3]);
tsout = detrend(tsin,'constant');
ans = 3×3

     3    -4     1
    -2     0     2
    -1     4    -3

Subtract the mean of each column for only the second and third columns of data.

tscol = detrend(tsin,'constant',[2 3]);
ans = 3×3

     8    -4     1
     3     0     2
     4     4    -3

Input Arguments

collapse all

Input timeseries containing 2-D data, specified as a scalar.

Data Types: timeseries

Detrend method, specified as one of the following options:

  • 'constant' — Subtract the mean from the data.

  • 'linear' — Subtract the best-fit line from the data.

Row or column indices, specified as a positive integer numeric scalar or vector. ind represents column indices for column-oriented data (tsin.IsTimeFirst is true) and represents row indices for row-oriented data (tsin.IsTimeFirst is false).

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

See Also

Introduced before R2006a

Was this topic helpful?