# Problem in data interpolation over different grids

7 views (last 30 days)
Federico on 9 Feb 2015
Commented: dpb on 13 Mar 2015
Hi all,
I'm currently being stuck on an interpolation problem, where I'm trying to compare observations and model data against each other by interpolating on a single grid.
- The model outputs a matrix of 900*900 points and the minima and maxima of both longitude and latitude. Since they are in UTM it's quite easy to create two linear vectors of size (1,900). Therefore what I have from the model is a matrix of scalar values (concentration of a chemical species) of 900*900 points and two vectors (latitude and longitude) of 1*900 points.
- My observations are instead in vector format: I have a vector of concentrations, one of UTM latitude and one of UTM longitude. I have various triplets of these concentrations-latitude-longitude vectors and, even if between triplets their length is different, within the same triplet each vector has the same length (i.e.: in the triplet 1, longitude is 1*128, latitude is 1*128 and concentration is 1*128). Latitude and longitude vectors are prepared in such a manner to be either monotonically increasing or decreasing.
What I was trying to do was to interpolate the observations on the model grid by using interp2, but I keep failing. Following there's an example:
obslat % <- the observations' latitude vector (1*128);
obslon % <- the observations' longitude vector (1*128);
obscon % <- the observations' concentration vector (1*128);
modlat % <- the model latitude vector (1*900);
modlon % <- the model longitude vector (1*900);
Vq=interp2(obslon,obslat,obscon,modlon,modlat,'linear',0);
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.
I'm pretty sure it's a trivial error, but even if I've read all the "Interpolating Gridded Data" MathWorks pages I still can't get out of it.
The product I'm using is Matlab R2013a.
Thanks all for the help!
EDIT: on dpb suggestion a small dataset (created using random numbers respecting the data characteristics) has been provided in attach. In the example we have the following variables
obslat <-observations' latitude
obslon <-observations' longitude
obsdata <-observations' concentrations
modlat <- model latitude
modlon <- model longitude
modata <- model concentrations
EDIT 2.0: I finally understood why MATLAB is throwing that error! The observation latitude and longitude are NOT evenly spaced...which is a huge problem since I can't simply linearize them with linspace without "moving" the physical position of my observations...
dpb on 11 Feb 2015
I disagree...the problem is that you still have only one vector of 100 points to associate with 100x100 grid; hence there's nothing for a 2D interpolation to use for the second dimension.
Again I repeat, take a small subsection (corner) of your actual data and paste it so we can look at it and the same for the corresponding area you wish to cover. Also show how you expect the one column of values of the chosen length to correlate across the two dimensions; there's your problem--you simply don't have enough information as is.

Erik S. on 9 Feb 2015
Hi
Look in the documentation for interp2. I think you need to use the meshgrid function on your vectors to form matrices used by interp2
dpb on 9 Feb 2015
...hink you need to use the meshgrid function on your vectors to form matrices used by interp2
No, as you say, from
help interp2
...
All the interpolation methods require that X and Y be monotonic and
plaid (as if they were created using MESHGRID). If you provide two
monotonic vectors, interp2 changes them to a plaid internally.
X and Y can be non-uniformly spaced.

dpb on 9 Feb 2015
What I was trying to do was to interpolate the observations on the model grid by using interp2, but I keep failing. Following there's an example:
obslat % <- the observations' latitude vector (1*128);
obslon % <- the observations' longitude vector (1*128);
obscon % <- the observations' concentration vector (1*128);
modlat % <- the model latitude vector (1*900);
modlon % <- the model longitude vector (1*900);
Vq=interp2(obslon,obslat,obscon,modlon,modlat,'linear',0);
obscon needs must be 128*128 array for the two vectors locations.
Also, to check your lon/lat input vectors, does
[Lat,Lon]=meshgrid(obslat,obslon);
succeed? You then need the obscon array that matches this "plaid" array.
dpb on 11 Feb 2015
Well, I had in mind a set of about 5 points total length for 3 or 4 positions and then the equivalent of a model and expected results that can be looked at to see what you're really after.
Show how the data vector is associated with the observations.

Erik S. on 9 Feb 2015
Try repmat like this:
obscon = repmat(obscon,128,1);

Federico on 13 Mar 2015
dpb was right: the best thing to do to accomplish the feat was not trying to interpolate the observations' vectors to the model matrix (as he said "you still have only one vector of 100 points to associate with 100x100 grid; hence there's nothing for a 2D interpolation to use for the second dimension"), but rather interpolate the 2D matrix on the observations' vectors (using interp2). Thanks all for the help and sorry if it took so long to finally post the results!
dpb on 13 Mar 2015
Thanks for the update...always nice to know the final resolution when there are apparent conundrums...

### Categories

Find more on Interpolation in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!