Removing NaN's from geoshow map
이전 댓글 표시
Hello all -
I am trying to map data using the geoshow function. My data has NaN values in it, that are totally blowing up my color ramp. The grid is only 96 x 112.
Any ideas on how to exclude the Nan data would be greatly appreciated.
Thanks!
답변 (2개)
the cyclist
2013년 2월 22일
0 개 추천
You might need to be a little bit more explicit about how you want to handle the NaNs. You can find where they are using the isnan() command. Would it be OK to simply remove entire rows or columns if they have a NaN in them?
If not, how do you want to handle it?
Youssef Khmou
2013년 2월 22일
편집: Youssef Khmou
2013년 2월 22일
hi,
I had the same problem before, i used to replace the NaN values only with 0.5 instead, but for your case if you truncate NaN elements you will face size problems , i recommend to replace NaN with mean neighborhood i+1 and i-1 :
% Given your grid as X (96 x 112)
X=randn(96,112);
% Spread some NaN in the grid
X(1:4:50,6:5:30)=NaN;
% Removing NaN
N=96*112;
X=reshape(X,1,N); % reshaping to use only One loop, although it is efficient
% to work with 2D to use the mean of [X(x-1,y), X(x+1,y), X(x,y+1), X(x,y-1)]
% Edges :
if isnan(X(1))
X(1)=0.5; % you give any value you want to edges
end
if isnan(X(end))
X(end)=0.5;
end
while sum(isnan(X))~=0
for x=2:N-1
if isnan(X(x))
X(x)=(X(x-1)+X(x+1))/2;
end
end
end
X=reshape(X,96,112); % go back to original form
Try this code and let me know, it has some disadvantages but it may work .
댓글 수: 2
ericsp
2013년 2월 28일
Youssef Khmou
2013년 3월 1일
편집: Youssef Khmou
2013년 3월 1일
ok ericsp, but i can not see the link you provided .
카테고리
도움말 센터 및 File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!