indices of all non zeros rows

조회 수: 31 (최근 30일)
Azza Ahmed
Azza Ahmed 2012년 5월 31일
Hi,
I have a large text file and I am trying to find the indices of the rows that do not have all zeros. For example is I have this matrix:
A= 5 3 1
0 0 0
5 7 9
0 0 0
4 0 0
0 0 0
2 0 0
1 0 1
1 0 0
To find the indices of rows with all zeros is by: find(all(A==0,2)) Which gives me this answer:2,4,6 Now, if someone can tell me how can I find the indices of the other rows which have values? e.g. for rows 1,3,5,7,8 and 9? Can someone please help me with a small code?
Best wishes
AA
[Edited to format array. -- the cyclist]
  댓글 수: 1
Honglei Chen
Honglei Chen 2012년 5월 31일
Your example shows a single vector, not a matrix. Could you format it correctly?

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2012년 5월 31일
find(~all(A==0,2))
  댓글 수: 4
Oleg Komarov
Oleg Komarov 2012년 6월 3일
idx = any(A,2)
A(idx,:)
Azza Ahmed
Azza Ahmed 2012년 6월 4일
That's exactly what I am looking for. Many thanks Oleg!
AA

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by