detect same value

how do I detect on the elements of a (:, 1) there is the same value?
a=[1 34;
2 33;
2 45;
3 32;
4 65;
4 99;
5 11;
1 33;
6 22]

 채택된 답변

Walter Roberson
Walter Roberson 2011년 6월 10일

0 개 추천

u = unique(a(:,1));
if length(u) ~= size(a,1)
%there were duplicates
end
If you want to find out which are equal to which,
bsxfun(@eq, a(:,1), a(:,1).'))
and that will return a logical matrix in which for row r, column c is set if a(r) == a(c)

댓글 수: 2

M M
M M 2013년 3월 6일
How would you isolate the duplicated values? So I would know which values are duplicated and use them for another purpose? (The opposite of the unique function)
setdiff(V, unique(V)) %for vector V, results are in sorted order
or
T = bsxfun(@eq, V(:), V(:).'); %for vector V
sum(T) > 1 %will be true at index K if V(K) is not unique

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

질문:

2011년 6월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by