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 Exchange에서 Linear 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