Deleting zeros and NaN in a matrix
이전 댓글 표시
I have a matrix containing zerros and NaN's. Now i want to delete the rows if it consists zero or Nan
for ex if i have a matrix
A=[2 3 36 9
Nan 54 20 23
85 69 10 30
20 Nan 20 30
1 0 8 20
2 6 8 9]
i want to delete rows containing zeros and Nan's
so i will have output as
out=[2 3 36 9
85 69 10 30
2 6 8 9]
Please help,i have matrix containing 1078x8 values
채택된 답변
추가 답변 (1개)
Kye Taylor
2012년 7월 13일
Try
A(any(isnan(A),2)|any(A==0,2),:) = []
댓글 수: 4
Pat
2012년 7월 14일
Walter Roberson
2012년 7월 14일
Only if you use the "raw" array, the third one returned by xlsread(). If you use the first array returned by xlsread() then it will be a numeric array rather than a cell array.
Pat
2012년 7월 14일
Walter Roberson
2012년 7월 14일
[num text raw]=xlsread('zz.xls');
A=num;
nanRows = any(isnan(A), 2)
zeroRows = any(A==0, 2)
badRows = nanRows | zeroRows
A(badRows, :) = []
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!