Remove lines from logical matrix if values in 3 or more rows are equal to 1.

If I have the matrix which has logical values
a = [0 0 0 0 0; 0 1 1 0 0; 1 1 0 1 1];
Then I would like to remove the last line as three or more values are 1 in them.

 Accepted Answer

More Answers (1)

Try this:
a = [0 0 0 0 0; 0 1 1 0 0; 1 1 0 1 1]
rowsToDelete = sum(a, 2) >= 3; % Change to == if you want.
a(rowsToDelete, :) = []

Categories

Asked:

on 23 Oct 2013

Commented:

on 23 Oct 2013

Community Treasure Hunt

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

Start Hunting!