Counting number of nonempty cells within a cell

4 views (last 30 days)
I have a 32x3 cell and I want to count the number of nonempty cells within it. When I use N = nnz(my_cell), this is the error I get
Undefined function 'nnz' for input arguments of type 'cell'.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Jul 2022
nnz(~cellfun(@isempty, my_cell))

More Answers (1)

David Hill
David Hill on 26 Jul 2022
nnz(cell2mat(my_cell));%assuming each cell is a number
  3 Comments
Walter Roberson
Walter Roberson on 26 Jul 2022
The question is not about nonzero cells, it is about nonempty cells, in a context where cells might contain different number of entries each. For example, length 5, length 0, length 3

Sign in to comment.

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!