Problem in data interpolation over different grids

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

1 Kommentar

dpb
dpb am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (4)

Erik S.
Erik S. am 9 Feb. 2015

1 Stimme

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

1 Kommentar

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

Melden Sie sich an, um zu kommentieren.

dpb
dpb am 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.

6 Kommentare

Federico
Federico am 9 Feb. 2015
Hi dpb and thanks for your answer,
yes I am able to create a grid of my lat/lon arrays using ndgrid or meshgrid, what I'm missing is how to correctly create the 128*128 obscon matrix: should I use a simple repmat on the obscon vector? Or is there a function to interpolate a vector on a grid?
dpb
dpb am 9 Feb. 2015
What's the point of 2D interpolation then, if there really is only a single vector of observations in 1D? Just use interp1 instead of interp2 and then replicate the result or just use 1D lookup instead of two.
Federico
Federico am 10 Feb. 2015
@dpb: probably it's just my misunderstanding of how interpolation problem works, but I would have used interp2 because while the observations are a 1*n vector, the model is a m*m matrix. And I want to somehow be able to match the two...
dpb
dpb am 10 Feb. 2015
And I'm having difficulty in understanding what, precisely there is to interpolate if there's only the one vector of data for a grid of points.
Give a (short) sample dataset and what you want to interpolate to; maybe that'll clarify the situation.
Federico
Federico am 10 Feb. 2015
done :-)
dpb
dpb am 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.

Melden Sie sich an, um zu kommentieren.

Erik S.
Erik S. am 9 Feb. 2015

0 Stimmen

Try repmat like this:
obscon = repmat(obscon,128,1);
Federico
Federico am 13 Mär. 2015

0 Stimmen

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!

1 Kommentar

dpb
dpb am 13 Mär. 2015
Thanks for the update...always nice to know the final resolution when there are apparent conundrums...

Melden Sie sich an, um zu kommentieren.

Produkte

Gefragt:

am 9 Feb. 2015

Kommentiert:

dpb
am 13 Mär. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by