How to count the number of repeat elements in a matrix

3 visualizaciones (últimos 30 días)
Yori Galisteu
Yori Galisteu el 16 de Sept. de 2019
Comentada: Yori Galisteu el 23 de Sept. de 2019
Hi there, i'm having a throuble with it:
I have the follow matrix:
M = [ Fa
Fa
Fa
Fa
Ka
Ka];
I wish to count how many times the symbols repeat and give me a answer like that: A = [ 4 2].
There's a way to do it? I already tried to search but the methods that i found is using numbers, but my matrix is composite with letters.

Respuesta aceptada

madhan ravi
madhan ravi el 16 de Sept. de 2019
M =["Fa"
"Fa"
"Fa"
"Fa"
"Ka"
"Ka"];
[~,~,c] = unique(M);
A = accumarray(c,1)

Más respuestas (0)

Categorías

Más información sobre MATLAB 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