How to count the number of repeat elements in a matrix

3 ビュー (過去 30 日間)
Yori Galisteu
Yori Galisteu 2019 年 9 月 16 日
コメント済み: Yori Galisteu 2019 年 9 月 23 日
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)
  1 件のコメント
Yori Galisteu
Yori Galisteu 2019 年 9 月 23 日
I take a bit long to answer. Thanks, it works!
:)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by