identify duplicate rows in a matrix
Show older comments
I have a matrix
A = [1 2 3; 3 4 5; 1 2 3];
I want to identify the duplicate row i.e. 3rd row and replace the values in that row by 0.
Resultant A = [1 2 3; 3 4 5; 0 0 0];
Is there an efficient way to do this? Thanks in Advance.
Accepted Answer
More Answers (1)
KSSV
on 6 Oct 2016
A = [1 2 3; 3 4 5; 1 2 3];
[C,ia,ic] = unique(A,'rows') ;
iwant = zeros(size(A)) ;
iwant(ia,:) = C ;
Categories
Find more on Shifting and Sorting 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!