Effacer les filtres
Effacer les filtres

how to count occurrences of a variable in a matrix?

1 vue (au cours des 30 derniers jours)
Võ Kiet
Võ Kiet le 6 Août 2021
Commenté : Võ Kiet le 6 Août 2021
Hi, I am stuck with my problem.
I have a matrix A = {'Red', 'Blue', 'Green', 'Yellow', 'White'; 'Red', 'Black', 'Purple', 'Red', 'White'}.
Now I want to count occurrences of 'Red' in this matrix. But I don't know how to count it. Please help me resolve this problem!
Thanks and Best Regards,
Kiet Vo

Réponse acceptée

KSSV
KSSV le 6 Août 2021
A = {'Red', 'Blue', 'Green', 'Yellow', 'White'; 'Red', 'Black', 'Purple', 'Red', 'White'} ;
nnz(strcmp(A,'Red'))
ans = 3
  1 commentaire
Võ Kiet
Võ Kiet le 6 Août 2021
nice!!! Thanks you so much, you saved me. Again, thanks so much.
Best Regards,
Kiet Vo

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by