finding duplicates

396 visualizaciones (últimos 30 días)
Danielle Leblanc
Danielle Leblanc el 5 de Ag. de 2011
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.

Respuesta aceptada

the cyclist
the cyclist el 5 de Ag. de 2011
Here is one way:
[uniqueA i j] = unique(A,'first');
indexToDupes = find(not(ismember(1:numel(A),i)))

Más respuestas (1)

Jan
Jan el 5 de Ag. de 2011
Another solution:
A = [1 1 2 2 3 3 3];
[U, I] = unique(A, 'first');
x = 1:length(A);
x(I) = [];
  2 comentarios
Oleg Komarov
Oleg Komarov el 5 de Ag. de 2011
Clever and simple.
Jan
Jan el 5 de Ag. de 2011
I'm inspired by Marsaglia's KISS random number generator: "Keep It Simple Stupid".

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by