How to count the number of repeat elements in a matrix

3 次查看(过去 30 天)
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.

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by