How do I make the movmean calculate the moving average at the start- and endpoints of an array but in conjunction to each other?

5 ビュー (過去 30 日間)
Currently my sample program is as following
A = [0 2 4 1 3 5 7];
M = movmean(A,[2 1])
For example, I want to find the moving average for A(7). Instead of not having value for the kf, I want the kf to consider the value of A(1) to calculate the moving average. And the same for when I want to find the moving average of A(1), it should consider the value of A(6) and A(7).
Is it possible to do so? If it is, any idea on how to do it?
Thank you very much.

採用された回答

Scott MacKenzie
Scott MacKenzie 2022 年 3 月 16 日
編集済み: Scott MacKenzie 2022 年 3 月 16 日
This seems to do the trick:
A = [0 2 4 1 3 5 7];
M = movmean(A,[2 1]);
M2 = movmean([A A A],[2 1]);
n = numel(A);
M2 = M2(n+1:n+n);
format shortg
[A; M; M2]
ans = 3×7
0 2 4 1 3 5 7 1 2 1.75 2.5 3.25 4 5 3.5 3.25 1.75 2.5 3.25 4 3.75

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by