MATLAB: How to calculate the value in a raster geodata matrix given the referencing matrix and the geographic co-ordinates in Mapping Toolbox 2.7 (R2008a)

Mapping Toolbox

I want to be able to calculate the altitude of a point in the raster data given the point's geographic coordinates (latitude and longitude) and the referencing matrix that comes with the raster data.
I was unable to use the LTLN2VAL function as it only accepts referencing vectors and not referencing matrices.

Best Answer

The example below illustrates how to calculate the altitude or value given a geographic location in raster geodata.
Assuming the raster geodata is stored in a matrix "topo" that stores altitudes in a world map:
[row, col] = latlon2pix(R,lat,lon);
Z = interp2(topo, col, row);
The code above first calculates the indices in the raster matrix corresponding to the provided (lat,lon) coordinates and then interpolates the data to estimate the altitude. The example attached below builds on the code above.