Create a moving average
24 ビュー (過去 30 日間)
古いコメントを表示
Hi There, How can I calculate a moving average for a column of data. For instance i want to average the 50 points either side of each data point in my column. Thanks
1 件のコメント
arman arefi
2020 年 3 月 27 日
You can use Moving Average Function in the FileExchange. Please find the link below:
採用された回答
Andrei Bobrov
2013 年 6 月 28 日
A - your data
L = filter(ones(101,1)/101,1,[A(:) zeros(50,1)]);
out = L(51:end);
0 件のコメント
その他の回答 (5 件)
Image Analyst
2013 年 6 月 28 日
編集済み: Image Analyst
2013 年 6 月 28 日
For a 1D column vector:
movingAverage = conv(yourSignal, ones(101,1)/101, 'same');
For a 2D array of columns:
movingAverage = conv2(yourSignal, ones(101,1)/101, 'same');
If you don't want the central pixel to be included in the average and have ONLY the 50 on either side, use
kernel = ones(101,1)/100;
kernel(51) = 0;
movingAverage = conv(yourSignal, kernel, 'same');
Same for a 2D matrix except use conv2 instead of conv. conv() and conv2() are highly optimized and very fast.
4 件のコメント
Nuchto
2017 年 11 月 30 日
So you could use ones(101,1) first, and onces it is convolved you can divide by 101?
Grzegorz Knor
2017 年 4 月 7 日
編集済み: Adam Danz
2021 年 9 月 19 日
1 件のコメント
Image Analyst
2017 年 4 月 7 日
True, and it offers some edge handling options ('shrink', 'discard', 'fill') that conv2() does not have.
conv2() also does not require any toolboxes because it's in base MATLAB.
Marc
2013 年 6 月 28 日
If you have the financial toolbox, doc movavg()....
[Short, Long] = movavg(Asset, Lead, Lag, Alpha)
0 件のコメント
the cyclist
2013 年 6 月 28 日
This page of the MATLAB documentation has an example of using the filter() command to calculate a moving average:
Jan
2013 年 6 月 28 日
There are many moving average filters in the FileExchange. Whenever a standard problem occurs, looking in the FEX is a good idea:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!