MATLAB Answers

length of arrey in cell and remove 0

1 view (last 30 days)
Na
Na on 21 Apr 2019
Edited: madhan ravi on 21 Apr 2019
A={[113],[112],[42],[29],[113],[69],[86],[0],[0]};
B={[18],[14],[5],[39],[27],[11],[9],[0],[0]};
C=cellfun(@(m,u) length(m)+length(u),A, B, 'uni',0);
as 2 last element in both A and B is 0
I want to have this result
C={[2],[2],[2],[2],[2],[2],[2],[0],[0]}

  0 Comments

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 21 Apr 2019
Edited: madhan ravi on 21 Apr 2019
A(cell2mat(A)==0)={[]}; % assuming each cell is scalar
B(cell2mat(B)==0)={[]};
C=cellfun(@(m,u) numel(m)+numel(u),A, B, 'un',0)

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.