How to find the lowest average of 3 consecutive numbers in a vector ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
StephenJ
am 8 Jan. 2017
Kommentiert: StephenJ
am 8 Jan. 2017
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.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 8 Jan. 2017
[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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!