Borrar filtros
Borrar filtros

how to count occurrences of a variable in a matrix?

1 visualización (últimos 30 días)
Võ Kiet
Võ Kiet el 6 de Ag. de 2021
Comentada: Võ Kiet el 6 de Ag. de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by