detect same value

2 次查看(过去 30 天)
pink
pink 2011-6-10
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
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)
Walter Roberson
Walter Roberson 2013-3-6
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 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by