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!

Answers (2)

the cyclist
the cyclist on 22 Feb 2013
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 Comment

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

Sign in to comment.

Youssef  Khmou
Youssef Khmou on 22 Feb 2013
Edited: Youssef Khmou on 22 Feb 2013
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 Comments

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 on 1 Mar 2013
Edited: Youssef Khmou on 1 Mar 2013
ok ericsp, but i can not see the link you provided .

Sign in to comment.

Categories

Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange

Products

Tags

Asked:

on 21 Feb 2013

Community Treasure Hunt

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

Start Hunting!