find zero and nonzero elemnt in cell
조회 수: 15 (최근 30일)
이전 댓글 표시
A={[21],[0],[32],[4],[60],[0],[0]};
B=A;
temp=cell2mat(A);
temp_1=find(temp==0);
B=cellfun(@(m,y) y(m)==0.1,temp_1,A, 'UniformOutput', false); % put 0.1 for zero element in A
temp_2=find(temp~=0);
B=cellfun(@(m,y) y(m)==0.2,temp_2,A, 'UniformOutput', false); % put 0.2 for nonzero element in A
result should be
result={[0,2],[0.1],[0.2],[0.2],[0.2],[0.1],[0.1]};
댓글 수: 0
채택된 답변
KSSV
2019년 5월 29일
A={[21],[0],[32],[4],[60],[0],[0]};
B=A;
idx = cellfun(@any,A) ;
B(idx) = {0.2} ;
B(~idx) = {0.1} ;
댓글 수: 1
Akira Agata
2019년 5월 29일
Another possible way:
A = {[21],[0],[32],[4],[60],[0],[0]};
B = A;
idx = cell2mat(B) == 0;
B(idx) = {0.1};
B(~idx) = {0.2};
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!