Azzera filtri
Azzera filtri

how to count occurrences of a variable in a matrix?

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by