Looping through numbers in file and adding first two numbers then next two and so on

1 visualización (últimos 30 días)
A = [1 2 3 4 5]
1+2 = 3
2+3 = 5
3+4 = 7
4+5 = 9
How can I loop through an array of numbers like above while storing the number everytime numbers are added? Thank you for any help!

Respuestas (2)

the cyclist
the cyclist el 1 de Ag. de 2019
A(1:end-1) + A(2:end)

Andrei Bobrov
Andrei Bobrov el 2 de Ag. de 2019
Editada: Andrei Bobrov el 2 de Ag. de 2019
conv(A,[1,1],'valid')
or
b = movsum(A,2);
out = b(2:end);

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by