add values in arrays with positive and zero values

조회 수: 1 (최근 30일)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2017년 2월 26일
댓글: Nikolas Spiliopoulos 2017년 2월 26일
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!!

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 2월 26일
a=[1 2 3 3 3];
b=[0 0 1 0 2];
c = a + cumsum(b);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by