If this value of 5x5 cell with vectors [106x1] are different to zeroes,count them e put the count in a matrix.
조회 수: 1 (최근 30일)
이전 댓글 표시
I have matchcounts (5x5)cell, every cell has a vector of double [106x1]. The vectors of double have zeros and non zero values. I want to find non zero values for every cell, count them and put the result in a matrix. I tried with this code:
a{i,j}(k,1)=[];
for k=1:106
for i=1:5
for j=1:5
if (matchcounts{i,j}(k,1))~=0
a{i,j}=a{i,j}(k,1)+1;
end
end
end
end
end
and others but it's not correct! Can you help me? Thanks Example: matchcounts(,1)(k,1) have 30 no zero values, the code have to count this no zero values and put 30 in the matrix in position (1,1): A(1,1)=30.
댓글 수: 0
채택된 답변
Stephen23
2015년 11월 13일
편집: Stephen23
2015년 11월 13일
>> X = {[0,1,0,2];[3,0,0,0];[0,4,5,6]};
>> Y = cellfun(@nnz,X)
Y =
2
1
3
>> sum(Y)
ans = 6
PS: if you don't actually need all of those intermediate values, why not use the much simpler and more efficient code that I gave to your last question:
idx = cellfun('isclass',TrajCompact,'char');
vec = 0:4;
for k = numel(vec):-1:1
rgx = sprintf('%d.+?%d',vec(k),vec(k));
tmp = regexp(TrajCompact(idx),rgx);
cnt(k) = sum(cellfun('prodofsize',tmp));
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!