Download the source code from here
http://www.osola.org.uk/elevations/index.htm
SRTMGeoTIFFReader.php is the clever file the reads the GeoTiff and converts the elevation values (in meters) into Lat/Lng coordinates.
I doubt this is exactly what you want but it does give you a solid base on understanding the process required to accomplish the task from your question.
(There is too much code to post here)
I suggest not to create such a matrix, which could be quite inefficient, but if you really need this, you create an ascii file with Long, lat, and value as columns, (which you can import in Matlab.)
gdal_translate -of XYZ input.tif output.asc
gdal is also available from qgis as a plugin (with a GUI), but you can use it directly as a command line.
Note that you can find your coordinates directly based on the row and column number. The easiest case is a starting from a matrix that is already in long/lat, in other words a regular grid in Lat/long coordinate system.
so you need to extract the upper left corner coordiantes, and the lat/long can be computed based on the index of you element
lat = upperLeftLat - Ysize*row
long = upperLeftLong + XSize*column
If you are not in this ideal case, you need to account for the rotation of the matrix and, potentially, the projection. But this can also be done "on the fly" without creating a new matrix (although if you need to reproject your data, it is better to do it first).
Best Answer
The code below is made for R and requires the raster library:
Storing your data as XYZ is rather inefficient, so expect a somewhat large file. You can potentially save some space by reducing the "accuracy" on the
round()
function, which is used to determine the number of digits in the X and Y coordinates.Another option is doing it with GDAL:
See http://www.gdal.org/frmt_xyz.html for more information on how to change the format of the output file.