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]};

 채택된 답변

KSSV
KSSV 2019년 5월 29일

0 개 추천

A={[21],[0],[32],[4],[60],[0],[0]};
B=A;
idx = cellfun(@any,A) ;
B(idx) = {0.2} ;
B(~idx) = {0.1} ;

댓글 수: 1

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개)

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

질문:

NA
2019년 5월 29일

댓글:

2019년 5월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by