Borrar filtros
Borrar filtros

Unique numbers in array

1 visualización (últimos 30 días)
Joseph Pauwels
Joseph Pauwels el 23 de Abr. de 2014
Respondida: Image Analyst el 24 de Abr. de 2014
I was charged to try and write my own unique function , I was thinking of first sorting the array, and then writing a loop that went through each number from min(min) to max(max) but cant figure out once a repeated number is identified to skip it. Any thoughts?

Respuesta aceptada

Image Analyst
Image Analyst el 24 de Abr. de 2014
That could work, but why use a for loop when there are so much more "MATLAB-ish" ways of doing it, like:
m = randi(4, 1, 11)
sortedm = sort(m)
diffs = [1, diff(sortedm)]
uniqueNumbers = sortedm(find(diffs))

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 23 de Abr. de 2014
Editada: Azzi Abdelmalek el 23 de Abr. de 2014
out= unique(A)
Or
out=unique(A,'rows')

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by