フィルターのクリア

Counting number of nonempty cells within a cell

27 ビュー (過去 30 日間)
Julia Gorman
Julia Gorman 2022 年 7 月 26 日
コメント済み: Walter Roberson 2022 年 7 月 26 日
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'.

採用された回答

Walter Roberson
Walter Roberson 2022 年 7 月 26 日
nnz(~cellfun(@isempty, my_cell))

その他の回答 (1 件)

David Hill
David Hill 2022 年 7 月 26 日
nnz(cell2mat(my_cell));%assuming each cell is a number
  3 件のコメント
David Hill
David Hill 2022 年 7 月 26 日
Attach your cell array.
for k=1:32;
for m=1:3;
a{k,m}=randi(30,1)-1;%a is a 32x3 cell array of numbers
end
end
N=nnz(cell2mat(a))
N = 94
Walter Roberson
Walter Roberson 2022 年 7 月 26 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by