MATLAB Answers

How to identify duplicate elements index values in this array without deleting them

3 views (last 30 days)
A=[53 54 80 1
21 43 12 0
27 71 14 0
52 55 70 23
36 69 26 0
46 66 38 0
68 78 60 0
59 3 48 0
74 7 42 0
42 17 74 0
67 30 64 0
64 35 67 0]
how to identify duplicate elements index values in this array without deleting them like 67 is repeated twice and so as 64

Accepted Answer

Image Analyst
Image Analyst on 25 Jul 2021
Try this:
A = [53 54 80 1
21 43 12 0
27 71 14 0
52 55 70 23
36 69 26 0
46 66 38 0
68 78 60 0
59 3 48 0
74 7 42 0
42 17 74 0
67 30 64 0
64 35 67 0]
minValue = min(A(:))
maxValue = max(A(:))
[counts, edges] = histcounts(A, minValue : maxValue)
for k = 1 : length(counts)
if counts(k) >= 2
fprintf('%f is in there %d times.\n', edges(k), counts(k));
end
end
You'll see:
0.000000 is in there 10 times.
42.000000 is in there 2 times.
64.000000 is in there 2 times.
67.000000 is in there 2 times.
74.000000 is in there 2 times.
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by