Simple Lookup function in 2D

I have a wave wx={wx1,wx2,...}, a wave wy={wy1,wy2,...} and a 2D wave ww of corresponding values ww={{w11,w12,w13...}{}...}.

Note that wx and wy are not regularly spaced.

I simply want to lookup the interpolated value (bilinear) of ww at a given point (xx,yy).

What is the most direct and efficient way?

Looking at the help content I only came up with using imageinterpolate , create a finer grid 2dwave and then use the values of ww corresponding to the wx_interp and wy_interp values closest to xx and yy.

Many thanks

To get a single value interpolated from a 2D wave, you can use the function Interp2d(). Note that Interp2D takes scaled X and Y values for the 2D wave, not point numbers. But if you have not applied wave scaling to the 2D wave, then (confusingly, perhaps) the X and Y values are actually point numbers. I presume that your X and Y waves have numbers of points that match the number of rows and columns of the 2D wave. In that case, you can get fractional point numbers to feed into Interp2d using the BinarySearchInterp function.

If it doesn't take too much memory, the ImageInterpolate method might be faster.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Here is why I did
    variable H_Rho_i=7.75
    variable H_T_i=52000
    make/o GDFT_Rho={4.5,5,6,7,8,9}
    make/o GDFT_T={20e3,30e3,40e3,5e4,6e4,7e4,8e4,9e4}
    make/o GDFT={{0.917460.92231 ,   0.91806 ,   0.9063, 0.88945},{0.83054   ,0.84908,   0.8469, 0.84473,    0.83536},{0.75753   ,0.78101,   0.78431,    0.79047 ,0.78952},{0.71312  ,0.73159,   0.74684,    0.75585,    0.7586},{0.67847    ,0.69593,   0.71717,    0.72416,    0.72929},{0.64918   ,0.66895,   0.68493,    0.69903,    0.70339},{0.62686   ,0.64619,   0.66138,    0.67573 ,0.68661},{0.60679  ,0.62896,   0.64265 ,0.65011    ,0.66453}}
 

How do I get the interpolated value of GDFT corresponding to H_T_i and H_Rho_i ?

Many thanks
Here is what I had in mind:
Function GetInterpolatedValue(xx, yy, xwave, ywave, wave2d)
    Variable xx, yy
    Wave xwave, ywave, wave2d
   
    Variable xp = BinarySearchInterp(xwave, xx)
    Variable yp = BinarySearchInterp(ywave, yy)
    return Interp2D (wave2d,  xp, yp)
end

But I see a problem- your wx and wy waves have one extra point. They were clearly made for our unevenly-spaced image display. But I'm afraid that isn't really suitable for interpolation (and certainly doesn't work well with my function). The distinction is whether the 2D wave values are interpreted to be values between one X value and the next X value (our image display) or if they are a value at a given value of X (which is how an interpolation interprets the matrix).

I suspect that you intend for the interpolation to work from the second interpretation, but you will have to come up with X and Y waves having one fewer point.

What value do you expect to get for (4.5, 20000)? Probably 0.91746. What value do you expect for (5,20000)? Probably 0.92231. What value do you expect to get for (9,20000)? For (8,20000)? It makes a difference whether the values are "values between" or "values at". For interpolation you need "values at".

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
You might want to consider ImageInterpolate after all. Just use it with the keyword XYWaves.

A.G.
WaveMetrics, Inc.