detrend
Removes the mean or best fit line from a data vector.
Syntax
R = detrend(x,p)
Inputs
- x
 - The data from which to remove a trend.
 - p
 - The following options are supported:
 
Outputs
- R
 - The result with the trend removed.
 
Examples
Example that removes the mean:
R = detrend([1,2,4,7,11,16],'constant')
      R = [Matrix] 1 x 6
-5.83333  -4.83333  -2.83333  0.16667  4.16667  9.16667
      Example that removes the best fit line:
R = detrend([1,2,4,7,11,16],'linear')
      R = [Matrix] 1 x 6
1.66667  -0.33333  -1.33333  -1.33333  -0.33333  1.66667
    Comments
When x is a matrix, the command operates on each column.
The linear trend is the best fit line is the ordinary least squares sense.