remove rows with all zeros

319 views (last 30 days)
Rahul
Rahul on 6 Jun 2012
Commented: Shishir Bapat on 11 Mar 2021
I have
a =
1 2 3
0 0 0
2 1 0
4 5 0
0 0 0
2 0 1
I need
b=
1 2 3
2 1 0
4 5 0
2 0 1

Accepted Answer

Walter Roberson
Walter Roberson on 6 Jun 2012
b = a(any(a,2),:);
  5 Comments
Mohamed Nedal
Mohamed Nedal on 20 Dec 2019
Hi Walter,
Would you please explain this line?
b = a(any(a,2),:);

Sign in to comment.

More Answers (1)

Geoff
Geoff on 6 Jun 2012
Search facility on Answers shows this question is asked a lot... Here's one of the more recent.

Products

Community Treasure Hunt

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

Start Hunting!