# sum of array elements with specific condition?

2 views (last 30 days)
MUKESH KUMAR on 29 Aug 2018
Commented: MUKESH KUMAR on 29 Aug 2018
lets say I had A=[1 0 1 1 0 1 0 1 0 0 1 1 1 1]; then I want B(1)=sum of all A elements, B(2)= sum all elements of A from A(2) excluding a(1), similarly for B(3) = sum of all A elements with excluding A(1),A(2) and so on...then B should be B=[9 8 8 7 7 6 5 5 4 4 4 3 2 1] thanks
##### 0 CommentsShow -1 older commentsHide -1 older comments

Sign in to comment.

### Accepted Answer

Stephen23 on 29 Aug 2018
>> fliplr(cumsum(fliplr(A)))
ans =
9 8 8 7 6 6 5 5 4 4 4 3 2 1
##### 0 CommentsShow -1 older commentsHide -1 older comments

Sign in to comment.

### More Answers (1)

jonas on 29 Aug 2018
Edited: jonas on 29 Aug 2018
This seems to be what you are after:
fliplr(cumsum(fliplr(A)))
ans =
9 8 8 7 6 6 5 5 4 4 4 3 2 1
5th digit is off. Could it be a mistake on your end?
##### 1 CommentShow NoneHide None
MUKESH KUMAR on 29 Aug 2018
sorry, that was my mistake and thanks

Sign in to comment.

### Categories

Find more on Multidimensional Arrays 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!