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
Ais a vector, thendetrendsubtracts the trend from the elements ofA.If
Ais a matrix, thendetrendoperates on each column separately, subtracting each trend from the corresponding column ofA.If
Ais a multidimensional array, thendetrendoperates column-wise across all dimensions, subtracting each trend from the corresponding column ofA.If
Ais a table or timetable with numeric variables of typesingleordouble, thendetrendoperates on each variable ofAseparately, subtracting each trend from the corresponding variable ofA.
You can use detrend functionality interactively by adding the
Find and Remove
Trends task to a live script.
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
Name-Value Arguments
Tips
The
detrendfunction 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,detrendtreats 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.
Alternative Functionality
Live Editor Task
You can use detrend functionality interactively by adding the
Find and Remove
Trends task to a live script.



