2

I have a tab separated XYZ file which contains 3 columns, e.g.

   586231.8       2525785.4           15.11
   586215.1       2525785.8            14.6
   586164.7         2525941           14.58
   586199.4       2525857.8           15.22
   586219.8         2525731            14.6
   586242.2       2525829.2           14.41

Columns 1 and 2 are the X and Y coordinates (in UTM meters) and column 3 is the associated Z value at the point X,Y; e.g. the elevation (z) at a point is given as z(x,y)

I can read in this file using dlmread() to get 3 variables in the workspace, e.g. X = 41322x1 double, but I would like to create a surface of size (m x n) using these variables. How would I go about this?

Following from the comments below, I tried using TriScatteredInterp (see commands below). I keep getting the result shown below (it appears to be getting some of my surface though): enter image description here

Any ideas what is going on to cause this result? I think the problem lies with themeshgrid command, though I'm not sure where (or why). I am currently putting in the following set of commands to calculate the above figure (my X and Y columns are in meters, and I know my grid size is 8m, hence ti/tj going up in 8s):

F = TriScatteredInterp(x,y,z,'nearest');
ti = ((min(x)):8:(max(x)));
tj = ((min(y)):8:(max(y)));
[qx,qy] = meshgrid(ti,tj);
qz = F(qx,qy);
imagesc(qz) %produces the above figure^
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
MBL
  • 1,197
  • 2
  • 11
  • 17

3 Answers3

3

I think you want the griddata function. See Interpolating Scattered Data in MATLAB help.

Nzbuu
  • 5,241
  • 1
  • 29
  • 51
  • Following from your suggestions I have used the [TriScatteredInterp](http://www.mathworks.co.uk/help/techdoc/ref/triscatteredinterp.html) function. Any ideas how I turn this into an actual surface though? – MBL Nov 24 '11 at 15:23
  • 2
    Follow the example in the help: http://www.mathworks.co.uk/help/techdoc/ref/triscatteredinterp.html – Nzbuu Nov 24 '11 at 15:30
  • I've added an image of my result into the original question. Any ideas what is going on? – MBL Nov 24 '11 at 18:09
1

Griddata and tirscattteredinterp are extremely slow. Use the utm2deg function on the file exchange and from there a combination of both vec2mtx to make a regular grid and then imbedm to fit the data to the grid. I.E.

for i = 1:length(X)
[Lat,Lon ] = utm2deg(Easting ,Northing ,Zone);
end 

[Grid, R] = vec2mtx(Lat, Lon, gridsize);
Grid= imbedm(Lat, Lon,z, Grid, R);
alex
  • 11
  • 1
0

Maybe you are looking for the function "ndgrid(x,y)" or "meshgrid(x,y)"

Oli
  • 15,935
  • 7
  • 50
  • 66