add values in arrays with positive and zero values

1 vue (au cours des 30 derniers jours)
Nikolas Spiliopoulos
Nikolas Spiliopoulos le 26 Fév 2017
Hi,
I have a two vectors a=[1 2 3 3 3], b=[0 0 1 0 2], I want to add them in such a way in order to get
c=[1 2 4 4 6] which means that i just add them if b=0 and if it's not I calculate the sum and put the result also in the next value for a. Then i add the next b
I don't know if it's clear
thanks!!

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 26 Fév 2017
a=[1 2 3 3 3];
b=[0 0 1 0 2];
c = a + cumsum(b);

Plus de réponses (0)

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by