How to find the lowest average of 3 consecutive numbers in a vector ?

2 ビュー (過去 30 日間)
StephenJ
StephenJ 2017 年 1 月 8 日
コメント済み: StephenJ 2017 年 1 月 8 日
Hi,
I need to find the lowest average of consecutive 3-value blocks (ie. (n,n+1,n+2), (n+1,n+2,n+3), (n+2,n+3,n+4) in a vector which has variable length (=number of elements does not have to be a multiple of the block size). Is there an easy way without using nested loops?
Thanks a lot.

採用された回答

Walter Roberson
Walter Roberson 2017 年 1 月 8 日
[minAvg, minidx] = min((V(1:end-2) + V(2:end-1) + V(3:end))/3);
This returns both the actual average and the location that it starts at.
  1 件のコメント
StephenJ
StephenJ 2017 年 1 月 8 日
That's exactly what I was looking for, shame I couldn't figure it out myself:) Thank you!

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

その他の回答 (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