How to print duplicate (repeated) value from an array?
4 次查看(过去 30 天)
显示 更早的评论
Dear experts,
I have to print the duplicate (repeated) value from the following array. Please help me.
104.96
81.01
-35.21
-150.76
145.22
104.96
20.62
-90.79
2 个评论
采纳的回答
Birdman
2018-1-4
编辑:Birdman
2018-1-4
More simpler way:
[C,~,~]=unique(v);
val=sum(v)-sum(C)
Edit after Image Analyst's warning:(works for any situation)
[C,~,idx]=unique(v,'stable');
n=accumarray(idx(:),1);
vals=C(find(n~=1))
3 个评论
Image Analyst
2018-1-4
Hareesha, it looks like you accepted Birdman's answer, and that doesn't require the stats toolbox, so go with that.
更多回答(2 个)
Image Analyst
2018-1-4
编辑:Image Analyst
2018-1-4
Here is one way:
v = [...
104.96
81.01
-35.21
-150.76
145.22
104.96
20.62
-90.79]
distances = pdist2(v, v) % In Stats toolbox
% Find where distances = 0
[rows, columns] = find(distances == 0)
for k = 1 : length(rows)
if rows(k) ~= columns(k) % Ignore diagonals
fprintf('Element at row %d (%f) is a repeat.\n', rows(k), v(rows(k)));
end
end
It shows:
Element at row 6 is a repeat.
Element at row 1 is a repeat.
Poornimadevi P
2018-1-26
hi, please help me to find duplication in sequence of image and send me a code .
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!