get rid of NaNs
조회 수: 1 (최근 30일)
이전 댓글 표시
I have two matrix A and B I want to remove all row and columns with all NaNa in matrix A and accordingly delete the same row and column in B:
A( all( isnan( A ), 2 ), : ) = []; % removes all rows with all nans
A( :, all( isnan( A ), 1 ) ) = []; % and columns
this remove all row and column with all NaNs, But I want to remove the exact row and column from B, too, here is an example:
>> A=[1 2 3 NaN NaN 5 6 7];
>> B=[1 2 3 4 5 6 7 8]; I want the B as below:
B=[1 2 3 6 7 8];
Thanks in advances!
댓글 수: 0
채택된 답변
per isakson
2012년 6월 7일
rows_to_be_removed = all( isnan( A ), 2 ),
A(rows_to_be_removed,:)=[];
B(rows_to_be_removed,:)=[];
etc.
Given that A and B have the same size.
댓글 수: 0
추가 답변 (2개)
Thomas
2012년 6월 7일
A=[1 2 3 NaN NaN 5 6 7];
B=[1 2 3 4 5 6 7 8];
check=find(isnan(A));
B(check)=[]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!