How to remove zero sum row from matrix

9 次查看(过去 30 天)
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]

采纳的回答

the cyclist
the cyclist 2017-1-24
编辑:the cyclist 2017-1-24
colToRemove = sum(A(2:end,:))==0;
A(:,colToRemove) = [];

更多回答(2 个)

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

请先登录,再进行评论。


Andrei Bobrov
Andrei Bobrov 2017-1-24
A = A(:,sum(A(2:end,:))~=0);

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by