find the number of occurances

2 visualizaciones (últimos 30 días)
johnson saldanha
johnson saldanha el 13 de Nov. de 2018
Comentada: johnson saldanha el 13 de Nov. de 2018
my matrix is x=[ 1 1 1 3 3 4 4 4 6 7]
i want the output as y=[ 3 2 3 1 1]
i want to find how many times a particular value is occuring

Respuesta aceptada

Stephan
Stephan el 13 de Nov. de 2018
Editada: Stephan el 13 de Nov. de 2018
y=sum(x(:)==unique(x))
Since 3 is occuring 2 times, the correct result is:
y=[3 2 3 1 1]
Best regards
Stephan
  6 comentarios
Stephan
Stephan el 13 de Nov. de 2018
if you dont get it to work with this, use madhans code below.
johnson saldanha
johnson saldanha el 13 de Nov. de 2018
yeah i tried that it works. thank you

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 13 de Nov. de 2018
x=[ 1 1 1 3 3 4 4 4 6 7]
u = unique(x) %unique numbers
y=histc(x,u) %occurences
bonus = [u; y]' %relation between them
  2 comentarios
johnson saldanha
johnson saldanha el 13 de Nov. de 2018
thanks.
madhan ravi
madhan ravi el 13 de Nov. de 2018
Anytime :)

Iniciar sesión para comentar.

Categorías

Más información sobre Logical 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