MATLAB: Find value (z) based on look up of coordinates (x,y)

coordinatesfindlook-upMATLAB

I have a 3-column matrix of data (A), where columns 1 and 2 are lats and longs, and column 3 is temperature.
I also have a 2-column matrix (B) of lats and longs.
I want to look up the lats and longs provided in matrix B in matrix A, and return the corresponding temperature value.
The lats and longs in B won't exactly match those in A, so I need the temperature value from the coordinates that are closest.
Any help would be appreciated.

Best Answer

Read about scatteredInterpolant
Let (x,y,z) be you data.
F = scatteredInterpolant(x,y,z,'nearest','none') ;
iwant = F(xi,yi) ; % where (xi,yi) is the location for which you want z
Related Question