Clear Filters
Clear Filters

Counting elements in cell array

3 views (last 30 days)
tinkiewinkie on 24 Jun 2020
Answered: Rohith Nomula on 24 Jun 2020
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?

Accepted Answer

KSSV on 24 Jun 2020
Edited: KSSV on 24 Jun 2020
If C is your cell array of strings.
n = nnz(strcmp(C,'cat'));

More Answers (1)

Rohith Nomula
Rohith Nomula on 24 Jun 2020
You can try this for a specific column of a cell array
Suppose in the 2nd column you have elements
This gives you count of all the labels name 'dog' in a specific column

Community Treasure Hunt

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

Start Hunting!