How to Find Column Duplicates

6 views (last 30 days)
RDG
RDG on 25 Jun 2014
Commented: Jos (10584) on 25 Jun 2014
Suppose:
A{1}=
2 3 1 2
2 1 1 3
2 3 2 4
2 5 2 5
2 6 2 6
2 2 5 2
How can I find the duplicate value and their indices for column 3? Resultant should be: Value: 1,2 Indices: Can be 1,3 --OR-- 1,2,3,4,5.
I tried unique but it returns 5 as well, which is something I don't want.
Gracias.

Accepted Answer

Jos (10584)
Jos (10584) on 25 Jun 2014
X = A{1}
X = X(:,3) % just column 3
[a,i,j] = unique(X) % find all unique elements
n = histc(j,1:numel(a)) % frequency
tf = n > 1 % Which occur more than once?
required result = a(tf) % select those
  2 Comments
RDG
RDG on 25 Jun 2014
Thanks for the prompt reply. What about the indices of those value? (2nd part of the question)
Jos (10584)
Jos (10584) on 25 Jun 2014
requiredindices = i(tf)

Sign in to comment.

More Answers (0)

Categories

Find more on Special Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!