Finding total count of values in a cell array?

I have a 4-D cell array, and there are empty arrays '[]' within it. How do I find the total number of the empty arrays?
This is what I tried.
% A is 4-D cell array
cnt = 0;
for a = 1:1:(size(A, 1))
for b = 1:1:(size(A, 2))
for c = 1:1:(size(A, 3))
for d = 1:1:(size(A, 4))
if A(a, b, c, d) == []
then cnt = cnt + 1;
end
end
end
end
end
Error: Undefined function or method 'eq' for input arguments of type 'cell'.
Someone please help me? Thanks.

4 件のコメント

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 13 日
To make your code work, change the if statement to
if isempty(A{a,b,c,d})
It seems that if you have x=cell(1);
x{1}==[] returns empty
Jason
Jason 2011 年 8 月 13 日
Thank you for pointing out, Fang!
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 13 日
First, to reference the content of a cell array, you need to use {}, not ()
To check if the content is empty, use isempty(), not to use ==[]
Jason
Jason 2011 年 8 月 13 日
Yes, I made a mistake, it should be A{a, b, c, d} - curly brackets, secondly, I learnt something new - the use of isempty. Thanks again.

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

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 13 日

1 投票

cnt=cellfun('isempty',A);
cnt=sum(cnt(:));

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by