Note: This page has been translated by MathWorks. Please click here

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Smooth response data

`yy = smooth(y)`

yy = smooth(y,span)

yy = smooth(y,* method*)

yy = smooth(y,span,

`method`

yy = smooth(y,'sgolay',degree)

yy = smooth(y,span,'sgolay',degree)

yy = smooth(x,y,...)

gpuarrayYY = smooth(gpuarrayY)

`yy = smooth(y)`

smooths the
data in the column vector `y`

using a moving average
filter. Results are returned in the column vector `yy`

.
The default span for the moving average is `5`

.

The first few elements of `yy`

are given by

yy(1) = y(1) yy(2) = (y(1) + y(2) + y(3))/3 yy(3) = (y(1) + y(2) + y(3) + y(4) + y(5))/5 yy(4) = (y(2) + y(3) + y(4) + y(5) + y(6))/5 ...

Because of the way endpoints are handled, the result differs
from the result returned by the `filter`

function.

`yy = smooth(y,span)`

sets
the span of the moving average to `span`

. `span`

must
be odd.

`yy = smooth(y,`

smooths
the data in * method*)

`y`

using the method `method`

`method`

| Description |
---|---|

| Moving average (default). A lowpass filter with filter coefficients equal to the reciprocal of the span. |

| Local regression using weighted linear least squares and a 1st degree polynomial model |

| Local regression using weighted linear least squares and a 2nd degree polynomial model |

| Savitzky-Golay filter. A generalized moving average with filter coefficients determined by an unweighted linear least-squares regression and a polynomial model of specified degree (default is 2). The method can accept nonuniform predictor data. |

| A robust version of |

| A robust version of |

`yy = smooth(y,span,`

sets
the span of * method*)

`method`

`span`

.
For the `loess`

and `lowess`

methods, `span`

is
a percentage of the total number of data points, less than or equal
to 1. For the moving average and Savitzky-Golay methods, `span`

must
be odd (an even `span`

is automatically reduced by `1`

).`yy = smooth(y,'sgolay',degree)`

uses
the Savitzky-Golay method with polynomial degree specified by `degree`

.

`yy = smooth(y,span,'sgolay',degree)`

uses
the number of data points specified by `span`

in
the Savitzky-Golay calculation. `span`

must be odd
and `degree`

must be less than `span`

.

`yy = smooth(x,y,...)`

additionally
specifies `x`

data. If `x`

is not
provided, methods that require `x`

data assume ```
x
= 1:length(y)
```

. You should specify `x`

data
when it is not uniformly spaced or sorted. If `x`

is
not uniform and you do not specify `method`

, `lowess`

is
used. If the smoothing method requires `x`

to be
sorted, the sorting occurs automatically.

`gpuarrayYY = smooth(gpuarrayY)`

performs
the operation on a GPU. The input `gpuarrayY`

is
a gpuArray column vector. The output `gpuarrayYY`

is
a gpuArray column vector. This syntax requires the Parallel
Computing Toolbox™.

You can use gpuArray x and y inputs with the smooth function,
but this is only recommended with the default `'method', 'moving'`

.
Using GPU data with other methods does not offer any performance advantage.

Another way to generate smoothed data is to fit it with a smoothing
spline. Refer to the `fit`

function
for more information.

Was this topic helpful?