I have
a =
1 2 3
0 0 0
2 1 0
4 5 0
0 0 0
2 0 1
I need
b=
1 2 3
2 1 0
4 5 0
2 0 1

 採用された回答

Walter Roberson
Walter Roberson 2012 年 6 月 6 日

17 投票

b = a(any(a,2),:);

5 件のコメント

Rahul
Rahul 2012 年 6 月 6 日
thanks Walter
Brodie Norfolk
Brodie Norfolk 2017 年 4 月 13 日
walter cheers mate
Walter Roberson
Walter Roberson 2017 年 10 月 10 日
Note: the above code treats nan values the same as zero values, so for example the row [0 nan nan] would also be removed. If that is not acceptable, then
b = a(any(a ~= 0,2),:);
Mohamed Nedal
Mohamed Nedal 2019 年 12 月 20 日
Hi Walter,
Would you please explain this line?
b = a(any(a,2),:);
Shishir Bapat
Shishir Bapat 2021 年 3 月 11 日
Thank you

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

その他の回答 (1 件)

Geoff
Geoff 2012 年 6 月 6 日

0 投票

Search facility on Answers shows this question is asked a lot... Here's one of the more recent.

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by