# detrend

Remove polynomial trend

## Syntax

## Description

`D = detrend(`

removes the
best straight-fit line from the data in `A`

)`A`

and returns the remaining data.

If

`A`

is a vector, then`detrend`

subtracts the trend from the elements of`A`

.If

`A`

is a matrix, then`detrend`

operates on each column separately, subtracting each trend from the corresponding column of`A`

.If

`A`

is a multidimensional array, then`detrend`

operates column-wise across all dimensions, subtracting each trend from the corresponding column of`A`

.If

`A`

is a table or timetable with numeric variables of type`single`

or`double`

, then`detrend`

operates on each variable of`A`

separately, subtracting each trend from the corresponding variable of`A`

.

`D = detrend(___,`

specifies
whether to include or omit `nanflag`

)`NaN`

values in `A`

for any of
the previous syntaxes. For example, `detrend(A,"omitnan")`

ignores
`NaN`

values when computing the trend. By default,
`detrend`

includes `NaN`

values.

`D = detrend(___,`

specifies additional parameters using one or more name-value arguments. For example,
`Name,Value`

)`detrend(A,1,bp,"Continuous",false)`

specifies that the fitted trend can
have discontinuities.

## Examples

## Input Arguments

## Tips

The

`detrend`

function subtracts the mean or a best-fit line (in the least-squares sense) from your data. If your data is tabular or contains several data columns or is a table or timetable,`detrend`

treats each data column separately.Removing a trend from the data enables you to focus your analysis on the fluctuations in the data about the trend. A linear trend typically indicates a systematic increase or decrease in the data. A systematic shift can result from sensor drift, for example. While trends can be meaningful, some types of analyses yield better insight once you remove trends.

Whether it makes sense to remove trend effects in the data often depends on the objectives of your analysis.

## Extended Capabilities

## Version History

**Introduced before R2006a**