Deleting zeros lines in a general matrix

5 views (last 30 days)
[EDIT: Wed May 25 03:56:06 UTC 2011 - Clarify - MKF]
Hello, I'm working with the Pinch Point Analysis modeling in MATLAB and have a problem. The user has to insert an (n,3) matrix when the M-file starts, like
A = [a11 a12 a13; a21 a22 a23; ... ; an1 an2 an3], for any n lines.
And at some point it will turn into a matrix with some zeros lines, which we don't know how many are or in which line they are.
Is it possible to delete only the zero lines from this matrix? If yes, how? Thanks.

Accepted Answer

Matt Fig
Matt Fig on 25 May 2011
A = rand(10,3)>.8 % Should have some zero rows.
A = A(any(A,2),:) % Take only the rows with a non-zero
Another way to do it is:
A(~any(A,2),:) = []

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!