MATLAB Answers

omit nonzero elemnt in cell

1 view (last 30 days)
Naime
Naime on 28 Jun 2019
Answered: Andrei Bobrov on 28 Jun 2019
A={[3,4],[8,9],[1,2],0,0,0};
A(cell2mat(A)==0)={[]};
I used this code, but have error
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 2)
m{n} = cat(2,c{n,:});
Result should be
A={[3,4],[8,9],[1,2],[],[],[]};

  0 Comments

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 28 Jun 2019
A(cellfun(@(x)numel(x) == 1 && x == 0,A)) = {[]};

  0 Comments

Sign in to comment.

More Answers (1)

Himanshu tripathi
Himanshu tripathi on 28 Jun 2019

  0 Comments

Sign in to comment.

Sign in to answer this question.