How to count the number of repeat elements in a matrix

3 views (last 30 days)
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.

Accepted Answer

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

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!