Add more nan values
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a matrix which may contains a region of nan values. I would like to surround the nan region with 0 boundary.
An example
A = 5 5 5 5; 5 5 nan 5; 5 5 5 5;
would become 5 0 0 0 ; 5 0 nan 0; 5 0 0 0;
Any help is appreciated
답변 (1개)
Youssef Khmou
2013년 3월 19일
편집: Youssef Khmou
2013년 3월 19일
hi try this standard version :
% Given
A = [5 5 5 5; 5 NaN 5 5; 5 5 5 5];
[N]=size(A);
for x=2:N(1)-1
for y=2:N(1)-1
if isnan(A(x,y))
%A(x-1:x+1,y-1:y+1)=0; not operational solution
A(x-1:x+1,y-1)=0;
A(x-1:x+1,y+1)=0;
A(x-1,y)=0;
A(x+1,y)=0;
end
end
end
A
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 NaNs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!