MATLAB Answers

Naime
0

put number in cell

Asked by Naime
on 24 May 2019
Latest activity Edited by madhan ravi
on 24 May 2019
A={[21],[],[32],[4],[60],[]};
length_A = cellfun(@(m) length(m),A,'uni',0);
B= cell(1, size(A,2));
B(cell2mat(length_A)) = 0.2;
'A' has empty elements, I want to put empty elements as 0 in B. For other element it should be 0.2
I want to have this result
B={[0.2],[0],[0.2],[0.2],[0.2],[0]};

  0 Comments

Sign in to comment.

2 Answers

madhan ravi
madhan ravi 님의 답변 24 May 2019
madhan ravi 님이 편집함. 24 May 2019
 채택된 답변

B = num2cell(~cellfun('isempty',A) * .2)

  0 Comments

Sign in to comment.


Catalytic
Catalytic 님의 답변 24 May 2019
Catalytic 님이 편집함. 24 May 2019

B=~cellfun('isempty',A)*0.2

  0 Comments

Sign in to comment.