MATLAB: Counting elements in cell array

MATLAB: Counting elements in cell array

cellcountelementlabel;

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?

Best Answer

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

    Your email address will not be published. Required fields are marked *