Select four surrounding grid points

I have the latitude and longitude location of a certain observation and a square latitude and longitude grid of model data. I need to calculate a bilinear interpolation of the 4 model grid points surrounding this observation to the observation. However I'm stuck on how to select these surrounding 4 grid points? Any ideas as to how I could do this in Matlab would be appreciated?
I've tried calculating the actual distance from the observation location and then selecting the 4 nearest points but I realised this doesn't necessarily select the 4 surrounding points.

Réponses (1)

Matt J
Matt J le 15 Fév 2013

0 votes

INTERP2 or griddedInterpolant() will do the entire interpolation operation for you.

5 commentaires

James
James le 15 Fév 2013
I have attempted this however my problem seems a bit more complex.
interp2 requires a grid of data in the meshgrid format. In turn meshgrid requires two vectors, one for latitude and one for longitude. However my data is not along lines of constant longitude and latitude. I have 2 matrices of dimension 219x289 one with the longitude information and one with the latitude information of each point. If I put these in meshgrid, i.e meshgrid(lat,lon), it computes a matrix 63219x63219. For interp2 I need a grid thats the same size as those lat and lon grids.
James
James le 15 Fév 2013
So, for the lat and lon grids, lat(i,j) corresponds to lon(i,j) for example.
Matt J
Matt J le 16 Fév 2013
Then how would bilinear interpolation be applicable to you? It sounds like you have scattered data and should be using TriScatteredInterp.
James
James le 17 Fév 2013
My data isn't scattered. It's a grid of data produced from a numerical weather prediction model. This produces a grid of points 45km apart placed over the pole of a polar stereographic projection of the earth.
Computations in weather prediction models are such that if you are trying to interpolate between the points you should take the surrounding 4, as these points pass information between each other and no others. I have an observation at a certain latitude and longitude so I need to interpolate information from these surrounding points to provide an estimate of what the model would predict (i.e. pressure or temperature) at the observation location. Hence bilinear interpolation.
Matt J
Matt J le 17 Fév 2013
Modifié(e) : Matt J le 17 Fév 2013
There appear to be a lot of contradictions now in what you're saying. Initially, you seemed to be saying that your lat(i,j) and lon(i,j) matrices do not contain plaid sample locations, as output from ndgrid/meshgrid. If they are not plaid, how can the data not be scattered? If they are plaid, there's no need to go through meshgrid/ndgrid. You should be able to use them in interp2/griddedInterpolant as is. They're either plaid or they're not plaid. They can't be neither or both. So which is it?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interpolation dans Centre d'aide et File Exchange

Question posée :

le 14 Fév 2013

Community Treasure Hunt

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

Start Hunting!

Translated by