필터 지우기
필터 지우기

Finding total count of values in a cell array?

조회 수: 4 (최근 30일)
Jason
Jason 2011년 8월 13일
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일
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일
cnt=cellfun('isempty',A);
cnt=sum(cnt(:));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by