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
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),:);
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 Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

태그

질문:

2012년 6월 6일

댓글:

2021년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by