find how many times duplicates occur in a matrix across row
2 ビュー (過去 30 日間)
古いコメントを表示
Given a matrix of 2xn dimension,in the row dimension there are several numbers with duplicates.Usnig histcnt these value shave their count atmost 2.
Now I would like to ensure that I only consider those elements in the row if their count is 1,for any number i will skip them.
I tried doing unique(A(1,:)) on my matrix but it didn't give me the correct result
My current code for duplicate findinng results in index exceed error
function ids=find_indices(A,B)
ids=[];
for i=1:size(A,2)
for j=1:size(B,2)
if(A(1,i-1)==A(1,i))
ctr=ctr+1;
end
%ctr=sum(A(1,:)==A(1,i));
if (B(1,j)==A(1,i) && ctr==1)
ids=[ids,i];
else
continue
end
end
end
end
5 件のコメント
回答 (1 件)
Jan
2021 年 9 月 21 日
As fas as I understand, you want to obtain the indices of the elements of A, which occur once only. Then:
index = ~isMultiple(A(1, :));
result = A(1, index); % Or maybe sorted:
sort(A(1, index)
function T = isMultiple(A)
[S, idx] = sort(A(:).');
m = [false, diff(S) == 0];
ini = strfind(m, [false, true]);
m(ini) = true; % Mark 1st occurence in addition
T(idx) = m;
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Preprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!