Remove lines from logical matrix if values in 3 or more rows are equal to 1.
Show older comments
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)
Image Analyst
on 23 Oct 2013
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
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!