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
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?

댓글 수: 1

ericsp
ericsp 2013년 2월 22일
Thanks for your input - I can not really remove any of the NaN cells. The represent water, and should be represented in the map.
Thanks- Eric

댓글을 달려면 로그인하십시오.

Youssef  Khmou
Youssef Khmou 2013년 2월 22일
편집: Youssef Khmou 2013년 2월 22일

0 개 추천

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

Thanks for your input -
Unfortunately these are still not working with the geoshow function.
I am able to get the worldmap to load, but once I use geoshow I get a single color for the map. The matrix shows up fine in imagesc.
cmap = colormap(jet)
worldmap([41 53],[-123 -109])
geoshow(demo, cmap, R)
here is the link to the sample file.
Any ideas?
Thanks!
Youssef  Khmou
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에 대해 자세히 알아보기

태그

질문:

2013년 2월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by