Hi suppose I have a column of different label of ant, cat, dog and fish formatted as cell in matlab, how do I count how many "ant", "dog","cat" and "fish" are there in total in the cell column?

 採用された回答

KSSV
KSSV 2020 年 6 月 24 日
編集済み: KSSV 2020 年 6 月 24 日

0 投票

If C is your cell array of strings.
n = nnz(strcmp(C,'cat'));

その他の回答 (1 件)

Rohith Nomula
Rohith Nomula 2020 年 6 月 24 日

0 投票

You can try this for a specific column of a cell array
Suppose in the 2nd column you have elements
labels=NameofYourCellArray(:,2);
nnz(ismember(labels,'dog'))
This gives you count of all the labels name 'dog' in a specific column

カテゴリ

ヘルプ センター および File ExchangeLinear Programming and Mixed-Integer Linear Programming についてさらに検索

質問済み:

2020 年 6 月 24 日

回答済み:

2020 年 6 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by