Problem 876. Sum the entries of each column of a matrix which satisfy a logical condition.
Given a numeric matrix A and a logical array L of the same size as A, return a row vector S containing the columnwise sums of the entries of A which satisfy L (i.e. where there is a true value in the logical array L). If L contains a column of false values, then the corresponding entry of S should be zero.
Examples:
1) If A = [1, 2; 3, 4] and L = [true false; false true], then S should be the row vector [1 4].
2) If A = triu(ones(3)) and L = logical(A), then S should be the row vector [1 2 3].
3) If A = repmat(1:3, 3, 1) and L = [false(3,1), true(3, 2)], then S should be the row vector [0 6 9].
Solution Stats
Problem Comments
Solution Comments
Show commentsGroup

Logic
- 17 Problems
- 13 Finishers
- Knights and Knaves (part 1)
- Knights and Knaves (part 2)
- Knights and Knaves (part 3)
- Knave in the middle attack
- Track Logic
- Hamiltonian Cycle
- Sum the entries of each column of a matrix which satisfy a logical condition.
- Find the starting index of a consecutive condition
- Find the next state of a JK Flip-Flop
- Find out next state (NS) of T Flip-Flop.
- Find out sum and carry of Binary adder
- What is the nth step in Conway's Life?
- Langston's Ant
- Kaggle: Reverse Game of Life - Single Move to One Cell Case
- Kaggle: Reverse Game of Life - Periods of Oscillators
- Kaggle: Reverse Game of Life - Zoo of Stills and Oscillators
- Kaggle: Reverse Game of Life - Create Isle prior State
Problem Recent Solvers163
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!