Summing elements of a vector without a for loop
Ältere Kommentare anzeigen
Given a vector/array v of length
, I would like to create a new vector of length M where the 1st component is the sum of the 1st 5 elements of v, the 2nd element is the sum of the next 5 elements of v,... and so on until we get to the last element which is the sum of the last 5 elements of v.
Is there a quick way to do this without using a for loop?
Akzeptierte Antwort
Weitere Antworten (1)
KSSV
am 29 Okt. 2021
1 Stimme
Read about movsum
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!