Remove repeated row in a matrix (specially zero's repeated row)

a =
1 4 6
0 0 0
6 7 3
0 0 0
3 1 2
0 0 0
0 0 0
Remove the repeated zero row.
I want this output
b=
1 4 6
0 0 0
6 7 3
3 1 2

1 Comment

ADD part
a=
[1 4 6
0 0 0
6 7 3
0 0 0
3 1 2
0 0 0
0 0 0
1 0 0]
b=
1 4 6
0 0 0
6 7 3
3 1 2
1 0 0

Answers (1)

EDIT
a = [1 4 6
0 0 0
6 7 3
0 0 0
3 1 2
0 0 0
0 0 0]
idx=find(~any(a,2))
a(idx(2:end),:)=[]

4 Comments

a=
[1 4 6
0 0 0
6 7 3
0 0 0
3 1 2
0 0 0
0 0 0
1 0 0]
if the matrix 1 0 0 row is in matrix means its also deleted in that code.. But it also include the output matrix
only 3 columns have zero means that repeated row only deleted
Ok, try this
idx=find(~any(a,2))
a(idx(2:end),:)=[]

This question is closed.

Asked:

on 4 Nov 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!