How to know the quatity of the number in an array

my data is:
A=[1 1 2 1 1 1 2 1 1 1 3 3 3 1 1 3 4 1 2 1 2 2 1 1 1 1 3 2 2 3 1 7 1 1 1 1 3 1 1 5 2 1 1 1 1 1 1 1 1 1 1 1 4 1 1 2 2 1 2 4 3 4 1 1 2 2 2 1 1 1 1 2 2 3 1 2 2 1 2 2 3 3 3 2 1 2 1 3 3 4 2 1 1 4 1 1 2 1 1 3 1 2 2 1 1 1 1 1 3 3 2 1 3 2 1 2 1 1 2 1 1 2 1 2 1 1 1 2 1 1 1 2 2 1 2 1 1 1 1 1 1 1 1 1 3 2 2 1 1 2 1 1 1 1 1 1 1 2 3 3 2 2 1 1 2 1 1 4 1 1 2 3 1 3 1 1 1 2 2 3 1 2 1 1 3 1 1 2 2 1 ]
I want to know how many times or the quantity of number 1 in my array.
thank you.

1 comentario

uncung fgv
uncung fgv el 16 de Mayo de 2013
am I missing this question?
I dont know exactly in english.
I want to know how many times the 1, or 2, or 3 ... is mentioned in that array.

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 16 de Mayo de 2013
out=sum(A(A==1))

7 comentarios

uncung fgv
uncung fgv el 16 de Mayo de 2013
Thankyou very much so simple.
You can skip the extraction:
sum(a==1)
Or:
nnz(a==1)
uncung fgv
uncung fgv el 16 de Mayo de 2013
but why is it wrong when I do it for number 2?
uncung fgv
uncung fgv el 16 de Mayo de 2013
it should be not sum?
Azzi Abdelmalek
Azzi Abdelmalek el 16 de Mayo de 2013
Editada: Azzi Abdelmalek el 16 de Mayo de 2013
Use the solution of Sean de Wolski
sum(a==2)
uncung fgv
uncung fgv el 16 de Mayo de 2013
actually I want:
how many times alphabet/number/character 2 is mentioned in that array.
not the sum/amount.
uncung fgv
uncung fgv el 16 de Mayo de 2013
yes, thank you. sean de wolski. your answer is hidden.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by