finding cells with positive values in a cell array with empty cells, cells of positive integers, and cells of nans

조회 수: 2 (최근 30일)
Dear Experts,
I would like to have the number and indices of cells with positive values in a cell array with cells of positive integers, empty cells and nans.
The solutions I have found in this topic were not suitable.
Please, find the array attached.
Many thanks
LG
  댓글 수: 2
dpb
dpb 2021년 3월 1일
"solutions I have found in this topic were not suitable."
So, what were those? No point in repeating the unwanted...
Levente Gellért
Levente Gellért 2021년 3월 1일
Dear dpb,
I was playing around with the following suggestions;
OutOfRange = (mycell > 0);
NrOutOfRange = sum(OutOfRange);
or
idx = find([mycell{:}] > 0);
or
idx = cellfun(@(x)~isempty(x) && x > 0, mycell);
Regards
lg

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

채택된 답변

dpb
dpb 2021년 3월 1일
편집: dpb 2021년 3월 1일
>> idx=cellfun(@(c)any(c>0),co_burst);
>> whos idx
Name Size Bytes Class Attributes
idx 856x340 291040 logical
>> sum(idx,'all')
ans =
72
>>
or, the locations...
>> [r,c]=ind2sub(size(idx),find(idx));
>> [r(1:5) c(1:5)]
ans =
5 1
8 4
31 13
34 15
55 25
>>

추가 답변 (1개)

Levente Gellért
Levente Gellért 2021년 3월 2일
Dear dpb, great, many thanks, works well. The 'all' option for sum works from 2018 I,think, but I could overcome the issue.
Thanks again.
Regards
lg

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by