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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!