Find duplicate elements and remove the rows that has similar values in one column
이전 댓글 표시
Dear Matlab experts,
I am using the following function to find the rows that has similar value in their 9th column. The speed of calculation is very slow as the data is big. Any suggestions for modifying my code to increase the speed or any other suggestions to achieve that purpose?
Thank you in advance.
function in1=dup_remove(out2)
b=[];
for i=1:size(out2,1)
[r,c]=find(out2(:,9)==out2(i,9));
if(length(r)==1)
b=[b;out2(i,:)];
end
end
if (~isempty(b))
in1=b;
end
end
댓글 수: 5
Fatih
2022년 10월 18일
I guess you may use
rowIndex = find(ismember(A(:,9),B,'rows'))
to find the row index of the searching vector.
In this code B matrix is searched in all 9th columns of A matrix. If there is a lot of B in A, then rowIndex will be a column vector. If the B is changing, you may set different values in every loop as you wish.
Hope it works for you.
Hamid
2022년 10월 19일
Hamid
2022년 10월 19일
Jan
2022년 10월 19일
@KSSV: How? I've tried it without success. The only way with standard Matlab functions I've found, uses unique to get a list of occurring values and histcounts to identify the elements, which occur once only. This was much slower than sorting the input, comparing neighbors by diff , remove the duplicates and reproducing the original order.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!