How to print duplicate (repeated) value from an array?
조회 수: 1 (최근 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 .
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!