title: MATLAB XYZ to Grid
body: <p>I have a tab separated XYZ file which contains 3 columns, e.g.</p>
  
  <pre><code>   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
  </code></pre>
  
  <p>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 <code>z(x,y)</code></p>
  
  <p>I can read in this file using <code>dlmread()</code> to get 3 variables in the workspace, e.g. <code>X = 41322x1 double</code>, but I would like to create a surface of size <code>(m x n)</code> using these variables. How would I go about this?</p>
  
  <p>Following from the comments below, I tried using <a href="http://www.mathworks.co.uk/help/techdoc/ref/triscatteredinterp.html" rel="nofollow noreferrer">TriScatteredInterp</a> (see commands below). I keep getting the result shown below (it appears to be getting some of my surface though):
  <img src="https://i.stack.imgur.com/uAI3g.jpg" alt="enter image description here"></p>
  
  <p>Any ideas what is going on to cause this result? I think the problem lies with the<code>meshgrid</code> 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):</p>
  
  <pre><code>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^
  </code></pre>