Cody

# Problem 876. Sum the entries of each column of a matrix which satisfy a logical condition.

Solution 1208322

Submitted on 8 Jun 2017 by Augusto Mazzei
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
A = [1 2; 3 4]; L = logical(eye(2)); S_correct = [1 4]; assert(isequal(columnwise_logical_sums(A, L), S_correct))

S = 1 0 0 4 S = 1 4

2   Pass
A = triu(ones(3)); L = logical(triu(ones(3))); S_correct = 1:3; assert(isequal(columnwise_logical_sums(A, L), S_correct))

S = 1 1 1 0 1 1 0 0 1 S = 1 2 3

3   Pass
A = repmat(1:3, 3, 1); L = [false(3,1) true(3,2)]; S_correct = [0 6 9]; assert(isequal(columnwise_logical_sums(A, L), S_correct))

S = 0 2 3 0 2 3 0 2 3 S = 0 6 9

4   Pass
A = 1:5; L = logical([0 1 0 1 0]); S_correct = [0 2 0 4 0]; assert(isequal(columnwise_logical_sums(A, L), S_correct))

S = 0 2 0 4 0

5   Pass
A = (1:5).'*(1:5); L = logical(diag(ones(1,4),-1)); S_correct = [2 6 12 20 0]; assert(isequal(columnwise_logical_sums(A, L), S_correct))

S = 0 0 0 0 0 2 0 0 0 0 0 6 0 0 0 0 0 12 0 0 0 0 0 20 0 S = 2 6 12 20 0

### Community Treasure Hunt

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

Start Hunting!