Filter löschen
Filter löschen

how to count occurrences of a variable in a matrix?

1 Ansicht (letzte 30 Tage)
Võ Kiet
Võ Kiet am 6 Aug. 2021
Kommentiert: Võ Kiet am 6 Aug. 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

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by