Cody

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

Solution 2003320

Submitted on 5 Nov 2019 by Doan Quang Manh
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))

b = 1 3 S = 1 b = 2 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))

b = 1 0 0 S = 1 b = 1 1 0 S = 1 2 b = 1 1 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))

b = 1 1 1 S = 0 b = 2 2 2 S = 0 6 b = 3 3 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))

b = 1 S = 0 b = 2 S = 0 2 b = 3 S = 0 2 0 b = 4 S = 0 2 0 4 b = 5 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))

b = 1 2 3 4 5 S = 2 b = 2 4 6 8 10 S = 2 6 b = 3 6 9 12 15 S = 2 6 12 b = 4 8 12 16 20 S = 2 6 12 20 b = 5 10 15 20 25 S = 2 6 12 20 0