How to count the number of repeat elements in a matrix

3 Ansichten (letzte 30 Tage)
Yori Galisteu
Yori Galisteu am 16 Sep. 2019
Kommentiert: Yori Galisteu am 23 Sep. 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.

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB 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