removal of doubles (both values)
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi all,
I have an nx3 matrix of values. The values are sorted and there are duplicates(never more than 1 duplicate).
If duplicates occur, I would like to replace both duplicates with a place holder..ex(0,0,0) ex
1 1 1
2 2 2
2 2 2
3 3 3
4 4 4
4 4 4
ans
1 1 1
0 0 0
0 0 0
3 3 3
0 0 0
0 0 0
Any thoughts would be very helpful, thanks
Answers (2)
Image Analyst
on 28 Oct 2011
I'm sure someone will come up with a one-liner, but here's a three-liner way
data = [1 1 1; 2 2 2; 2 2 2; 3 3 3; 4 4 4; 4 4 4; 4 4 4]
duplicateRows = diff(data(:,1)) == 0
duplicateRows = [duplicateRows;0] | [0; duplicateRows]
data(duplicateRows,:) = 0
1 Comment
matt
on 1 Nov 2011
Fangjun Jiang
on 28 Oct 2011
This is one way to do it.
a=[1 1 1
2 2 2
2 2 2
3 3 3
4 4 4
4 4 4];
[ua,indI,indJ]=unique(a,'rows');
DupRows=setdiff(1:size(a,1),indI);
index=[DupRows,DupRows+1];
a(index,:)=0;
1 Comment
matt
on 1 Nov 2011
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!