Main Content

detrend

Subtract mean or best-fit line fromtimeseriesobject

Description

example

tsout = detrend(tsin,method)subtracts either a mean or a best-fit line from 2-D data in atimeseriesusing the specifiedmethod, and also removes allNaNvalues.

example

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

Examples

collapse all

创建一个timeseriesobject with 2-D data, and subtract the mean of each column from the data.

A = magic(3)
A =3×38 1 6 3 5 7 4 9 2
tsin = timeseries(A,[1 2 3]); tsout = detrend(tsin,'constant'); tsout.Data
ans =3×33 -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]); tscol.Data
ans =3×38 -4 1 3 0 2 4 4 -3

Input Arguments

collapse all

Inputtimeseriescontaining 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.indrepresents column indices for column-oriented data (tsin.IsTimeFirstistrue) and represents row indices for row-oriented data (tsin.IsTimeFirstisfalse).

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

版本History

Introduced before R2006a

See Also