Add more nan values

2 次查看(过去 30 天)
Mr X
Mr X 2013-3-19
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 个评论
Jan
Jan 2013-3-19
What should happen for two neighboring NaNs?

请先登录,再进行评论。

回答(1 个)

Youssef  Khmou
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

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by