Incremental summation of vector
Show older comments
If A = [1 2 3 4 5 6 7 8 9];
Then how to get B = [A(1)+A(2), A(2)+A(3), A(n-1)+A(n)]; with a single command or short code ??
Accepted Answer
More Answers (1)
The + operator can add vectors.
A = 1:10;
B = A(1:end-1)+A(2:end)
1 Comment
Walter Roberson
on 1 Apr 2021
... which is probably the answer expected for the homework ;-)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!