Removing rows with identical column value
Show older comments
Hello. I have a 2 x 3 matrix.
I want to delete all rows which have the same elements in column 3.
For instance: a = [2,7; 3,4; 3,7] => [3,4]
In this case, as number 7 was repeated in row 1 and row 3, both rows are removed.
Thanks in advance.
Accepted Answer
More Answers (1)
Star Strider
on 27 Dec 2015
a = [2,7; 3,4; 3,7];
[Au,ia,ic] = unique(a(:,2), 'stable');
rep = accumarray(ic, 1);
rows = find(ic == ic(rep<2));
Result = a(rows,:)
Result =
3 4
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!