Cody

Solution 1830420

Submitted on 29 May 2019
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   Fail
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))

Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'. Error in columnwise_logical_sums (line 3) S = ones(1,length(L))*c; Error in Test4 (line 3) 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))