필터 지우기
필터 지우기

How to count the number of zero subcells in a cell?

조회 수: 4 (최근 30일)
Fateme Jalali
Fateme Jalali 2016년 1월 18일
댓글: Star Strider 2016년 1월 18일
I have a cell array 12*32. each element of my cell contains 32 data. for example C{11,32}='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ' . I want to count how many of zero array like above is there in my cell. could any one help me? thanks
  댓글 수: 3
Fateme Jalali
Fateme Jalali 2016년 1월 18일
t1 and t2 are my database.In this code I want to count howmany '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0' happens in diffrcell

댓글을 달려면 로그인하십시오.

답변 (2개)

Thorsten
Thorsten 2016년 1월 18일
편집: Thorsten 2016년 1월 18일
If you have a cell array of matrices:
C{1,1} = ones(1,32);
C{1,2} = 2*ones(1,32);
C{2,1} = zeros(1,32);
C{2,2} = zeros(1,32);
N = nnz(cellfun(@(x) nnz(x)==0, C));
If you have a cell array of cells, an additional cell2mat is needed:
C = {{rand(5,1)}, {rand(7,1)}, {zeros(6,1)}, {rand(7,1)}, {0 1 2 3}, {-1 1}};
N = nnz(cellfun(@(x) nnz(cell2mat(x))==0, C));

Walter Roberson
Walter Roberson 2016년 1월 18일
Most of the code can be replaced.
tt2u = unique(tt2{1}, 'rows');
tt3u = unique(tt3{1}, 'rows');
number_of_similar_chunks = sum( ismember(tt2u, tt3u) );
However you should clarify how you want the counting to occur if there are duplicate entries in one of the array that match the other array.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by