identify duplicate rows in a matrix
46 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Massimo Zanetti
2016-10-6
You can identify the repeated rows by invoking unique function of Matlab, and then set to 0 non-unique rows as follows:
[C,ia,ib]=unique(A,'rows','stable');
i=true(size(A,1),1);
i(ia)=false;
A(i,:)=0;
Then A will be your output.
0 个评论
更多回答(1 个)
KSSV
2016-10-6
A = [1 2 3; 3 4 5; 1 2 3];
[C,ia,ic] = unique(A,'rows') ;
iwant = zeros(size(A)) ;
iwant(ia,:) = C ;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!