Fill NaN cells using surrounding data values
이전 댓글 표시
Hi,
I would like to fill NaN cells in the rows of a matrix with the mean of the immediately surrounding values.
For example I would like to convert
>> A=magic(5);
>> A(:,2:4)=NaN;
>> A(1:2,:)=NaN;
>> A
A =
NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
4 NaN NaN NaN 22
10 NaN NaN NaN 3
11 NaN NaN NaN 9
>>
To this:
>> A
A =
NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
4.0000 13.0000 13.0000 13.0000 22.0000
10.0000 6.5000 6.5000 6.5000 3.0000
11.0000 10.0000 10.0000 10.0000 9.0000
>>
Only converting those NaN cells that are surrounded on the row by non-NaN values.
I hope this is clear.
Thanks very much
채택된 답변
추가 답변 (2개)
Image Analyst
2011년 8월 3일
0 개 추천
It can't be that hard - did you know there is an "isnan()" function, as well as mean() and sum()? Give it a shot yourself first - it's not hard.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!