How to remove zero sum row from matrix

4 Ansichten (letzte 30 Tage)
Vishal Sharma
Vishal Sharma am 24 Jan. 2017
Beantwortet: Andrei Bobrov am 24 Jan. 2017
A=[1 2 3 4 5 6;
0 0 1 1 0 1;
0 0 1 0 1 0]
Sum of second and third row if equal to zero, then in new matrix that column is to be excluded. So, the result shall be
A=[3 4 5 6;
1 1 0 1;
1 0 1 0]

Akzeptierte Antwort

the cyclist
the cyclist am 24 Jan. 2017
Bearbeitet: the cyclist am 24 Jan. 2017
colToRemove = sum(A(2:end,:))==0;
A(:,colToRemove) = [];
  1 Kommentar
the cyclist
the cyclist am 24 Jan. 2017
Edited my answer so that it will sum all rows except the first one.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Roger Stafford
Roger Stafford am 24 Jan. 2017
A = A(:,(A(2,:)+A(3,:)~=0));
  1 Kommentar
Vishal Sharma
Vishal Sharma am 24 Jan. 2017
Thanks Roger Stafford,,, if there are n rows, please also suggest answer...

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
Andrei Bobrov am 24 Jan. 2017
A = A(:,sum(A(2:end,:))~=0);

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by