finding duplicates

468 ビュー (過去 30 日間)
Danielle Leblanc
Danielle Leblanc 2011 年 8 月 5 日
回答済み: Nakshathra 2022 年 9 月 29 日
A=[ 1 1 2 2 3 3 3];
unique(A)=[1 2 3]; but I want to find the duplicates that are not the first occurrence. i.e x=[2 4 6 7]; I typed help unique but I couldn't figure out if I and J reported by this function helps with my purpose.I know that I can program it but i want to be as efficient as possible in my codes to reduce the running time.

採用された回答

the cyclist
the cyclist 2011 年 8 月 5 日
Here is one way:
[uniqueA i j] = unique(A,'first');
indexToDupes = find(not(ismember(1:numel(A),i)))

その他の回答 (2 件)

Jan
Jan 2011 年 8 月 5 日
Another solution:
A = [1 1 2 2 3 3 3];
[U, I] = unique(A, 'first');
x = 1:length(A);
x(I) = [];
  2 件のコメント
Jan
Jan 2011 年 8 月 5 日
I'm inspired by Marsaglia's KISS random number generator: "Keep It Simple Stupid".

サインインしてコメントする。


Nakshathra
Nakshathra 2022 年 9 月 29 日
[uniqueA i j] = unique(A,'first');
indexToDupes = find(not(ismember(1:numel(A),i)))indexToDupes = find(not(ismember(1:numel(A),i)))

カテゴリ

Find more on Large Files and Big Data 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!

Translated by