How to count the number of different strings in a string list?

Dear All
I would need some help on this:
I have the following string list:
AAA
ABB
CDE
ABB
CCR
AAA
FDR
I would need to count the different strings in this list which is, in this example 5, and this would be my output.
The acual list may have undreds of strings.
Many thanks in advance!
Para

 採用された回答

Mischa Kim
Mischa Kim 2021 年 1 月 18 日

0 投票

Hi, use
str = {'AAA','ABB','CDE','ABB','CCR','AAA','FDR'};
numstr = numel(unique(str))

3 件のコメント

Paramonte
Paramonte 2021 年 1 月 18 日
Dear Mischa
Thank you for your speedy reply.
Your solution worked for us.
Regards
Richard Cornish
Richard Cornish 2021 年 4 月 15 日
This is useful. I want a frequency plot of each unique string - any ideas?
str = {'AAA','ABB','CDE','ABB','CCR','AAA','FDR'};
histogram(categorical(str))

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Characters and Strings についてさらに検索

製品

リリース

R2019b

タグ

質問済み:

2021 年 1 月 18 日

コメント済み:

2021 年 4 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by