Moving Average Function using a sliding window

2 ビュー (過去 30 日間)
Patrick Carey
Patrick Carey 2015 年 3 月 30 日
回答済み: Image Analyst 2015 年 3 月 31 日
Implement the moving average function, using a fixed window size of 10. Input variables: x – A vector containing a series of values that are to be smoothed. Output variables: y – A vector the same size as x, which contains the moving average. The elements of y satisfy:
y(i) = average of elements of x at positions from 1 to i, if 1 i 10; and
y(i) = average of elements of x at the 10 positions leading up to and including i, if i > 10.
  2 件のコメント
Jan
Jan 2015 年 3 月 30 日
編集済み: Jan 2015 年 3 月 30 日
This is not a question, but a command. You will not have success when you copy your homework assignment in a forum. See Answers: Homework questions
Patrick Carey
Patrick Carey 2015 年 3 月 31 日
Okay, I understand. I have already solved this particular problem by myself anyway.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2015 年 3 月 31 日
For what it's worth, I would have used conv() twice and divided them. Not sure how you did it. If you have the Curve Fitting Toolbox, you could use smooth()
Description
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

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by