フィルターのクリア

Computing the mean over 3 numbers in a vector

13 ビュー (過去 30 日間)
Lily
Lily 2014 年 3 月 5 日
回答済み: Rick Rosson 2014 年 3 月 5 日
Hi
I have a vector that I want to find the average over each 3 numbers. So if I have a vector A and sampling it over 3 I would get new_A. However my solution isn't working. Could you help me?
A = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]; %The vector
count = 1;
for i = 1:3:length(A)
new_A(count) = mean(A(i:i+1));
count = count+1;
end
new_A = [2 5 8 11 14]; %The desired ouput

採用された回答

Rick Rosson
Rick Rosson 2014 年 3 月 5 日
... = mean(A(i:i+2));

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 3 月 5 日
Sliding window or each distinct group of 3? If it is each distinct group of 3, then reshaping to 3 x something and then mean() along the dimension you made 3.

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by