Using movmean to calculate mean of first and last element in array

8 ビュー (過去 30 日間)
sr9497
sr9497 2022 年 3 月 22 日
コメント済み: Ive J 2022 年 3 月 22 日
I have an array [1 5 8 10] and using movmean with window length [0 1] this gives me [3 6.5 9 10]. Is there a way in which I can use movmean to calculate the mean of 10 and 1 as well and add that in the fourth position of the array?

採用された回答

Ive J
Ive J 2022 年 3 月 22 日
What about this?
a = [1 5 8 10];
ma = movmean([a, a(1)], [0 1], 'Endpoints', 'discard')
ma = 1×4
3.0000 6.5000 9.0000 5.5000
  2 件のコメント
sr9497
sr9497 2022 年 3 月 22 日
編集済み: sr9497 2022 年 3 月 22 日
Thank you! Do you know how I could change this so it also works for a matrix? Then for every column.
Ive J
Ive J 2022 年 3 月 22 日
Just set dim to 2:
a = [1 5 8 10;3 4 5 12];
ma = movmean([a, a(:, 1)], [0 1], 2, 'Endpoints', 'discard')
ma = 2×4
3.0000 6.5000 9.0000 5.5000 3.5000 4.5000 8.5000 7.5000

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by