findduplicates

버전 1.3.1.0 (15.8 KB) 작성자: Erik
Find linear indices of duplicate elements in input.
다운로드 수: 86
업데이트 날짜: 2018/1/20

findduplicates, find linear indices of duplicates in input
This function accepts the same input arguments as the unique function, which is the basis for this function.

Syntax

[i1, i2] = findduplicates(A)
[i1, i2] = findduplicates(A, setOrder)
[i1, i2] = findduplicates(A, occurence)
[i1, i2] = findduplicates(A, _, 'rows')
[i1, i2] = findduplicates(A, 'rows', _)
[i1, i2, C, ia, ic] = findduplicates(_)

[i1, i2, C, ia, ic] = findduplicates(A, 'legacy')
[i1, i2, C, ia, ic] = findduplicates(A, 'rows', 'legacy')
[i1, i2, C, ia, ic] = findduplicates(A, occurrence, 'legacy')
[i1, i2, C, ia, ic] = findduplicates(A, 'rows', occurrence, 'legacy')
[i1, i2, C, ia, ic] = findduplicates(A, occurrence, 'rows', 'legacy')

Description

[i1, i2] = findduplicates(A) finds the linear indices of duplicates in input A. The accepted input arguments are the same as accepted by the unique function. The first output, i1, contains the linear indices of the first duplicate elements into A that correspond to the duplicates indexed by i2, the second output. i1 may contain the same index multiple times if an element exists more than twice in A. If no duplicates exist, i1 and i2 are returned empty.

[i1, i2] = findduplicates(A, setOrder) supports the 'sorted' (default) or 'stable' flags of the unique function, but have no effect to find duplicates.

[i1, i2] = findduplicates(A, occurence) specifies which duplicate to consider as the first, occurence can be 'first' (default) or 'last'.

[i1, i2] = findduplicates(A, _, 'rows') and [i1, i2] = findduplicates(A, 'rows', _) treat each row of A as a single entity and returns indices of duplicate rows. You must specify A and optionally can specify setOrder or occurence. The 'rows' option does not support cell arrays.

[i1, i2, C, ia, ic] = findduplicates(_) also returns C, ia and ic such that [C, ia, ic] = unique(_). See the documentation for unique for their meaning and use.

The syntaxes with the 'legacy' option preserve the behaviour this function would have on R2012b and prior releases. The 'legacy' option must be the last input argument. It does not support categorical arrays, datetime arrays, duration arrays, tables or timetables.

Examples

Find the first indices of duplicates and the other duplicates' indices:

A = [9, 2, 9, 5]
[i1, i2] = findduplicates(A)

Result

A =
9 2 9 5
i1 =
1
i2 =
3

This indicates that the first element in A has a duplicate at the third element.

Find the last indices of duplicate character arrays and the other duplicates' indices:

names = {'Charlie', 'Alice', 'Bob', 'Alice', 'Alice', 'Charlie'};
[i1, i2] = findduplicates(names, 'last')

Result

i1 =
6
5
5

i2 =
1
2
4

This indicates that the character arrays at indices 6 and 5 have duplicates, 5 having two duplicates. The duplicate for index 6 is at index 1, the duplicates for index 5 are at indices 2 and 4.

More examples

Run findduplicatesdemo for more examples of findduplicates based on the examples of the unique function. See the contents of findduplicatesdemo.m for details.

Notes

NaN are considered as distinct values by the unique function, thus they are considered non-duplicates by findduplicates as well.

Licence

GNU GPLv3

인용 양식

Erik (2024). findduplicates (https://github.com/erikhuizinga/findduplicates), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2014b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

GitHub 디폴트 브랜치를 사용하는 버전은 다운로드할 수 없음

버전 게시됨 릴리스 정보
1.3.1.0

This release supports new MATLAB syntax.

The documentation has been greatly improved and extended. For example, examples have been added.

1.2.0.0

Update formatting

1.1.0.0

Fixes help text typos
-
Connected to GitHub and updated the description text.
-

1.0.0.0

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.