Cody

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

Solution 1227272

Submitted on 8 Jul 2017 by yurenchu
• Size: 10
• This is the leading solution.
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))

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

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))

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))

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))