How to remove zero sum row from matrix

2 ビュー (過去 30 日間)
Vishal Sharma
Vishal Sharma 2017 年 1 月 24 日
回答済み: Andrei Bobrov 2017 年 1 月 24 日
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) = [];
  1 件のコメント
the cyclist
the cyclist 2017 年 1 月 24 日
Edited my answer so that it will sum all rows except the first one.

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by