Clear Filters
Clear Filters

Remove row of cell array that contains 0.

4 views (last 30 days)
For example, I have a = [{0} {0} {0}; {1} {3} {4}; {0} {0} {0}]. I would like to remove the row that contains all of zero so that I can have the result a = [{1} {3} {4}]. I try this but it not work.
a(all(a == 0, 2), :) = []
what I am missing? Thanks.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 16 Jan 2012
out = a(all(cellfun(@(x)x~=0,a),2),:);
OR
out = a(all(cell2mat(a) ~= 0,2),:);
  1 Comment
Chin
Chin on 14 Feb 2012
I would like to know if my cell array is a = [{0} {2} {3}; {0} {4} {5}; {0} {7} {3}], how do i delete the column that contains all of 0? thanks again.

Sign in to comment.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!