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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by