3D Data Gridding in Excel


=GRIDXYZ(xy, z, grid_x, grid_y, [options])

GRIDXYZ is a powerful 3D data gridding function based on natural neighbor interpolation algorithm. It can be used to map a set of scattered data points onto a uniform rectilinear grid for the purpose of plotting a 3D surface in Excel.

Use GRIDXYZ to map set of scattered (x,y,z) data points onto a uniform rectilinear grid

GRIDXYZ automatically sorts your data set and averages the z values if your data set contains duplicate (x,y) points.

Required Inputs

xy a 2-column array of scattered (x,y) points coordinates.

z a vector of corresponding z values

grid-x a row-vector containing the uniform x-coordinates for the rectilinear grid.

grid-y a column-vector containing the uniform y-coordinates for the rectilinear grid.

The x- and y-coordinates vectors must be arranged as shown. The yellow range will hold the interpolated grid z values for each (xi,yi) grid point. You must run GRIDXYZ as an array formula in the yellow range.


Optional Inputs

ctrl a set of key/value pairs for algorithmic control as detailed below.

Description of key/value pairs for algorithmic control

Admissible Values (Boolean)True or False
Default ValueTrue
RemarksA True value will slightly perturb the locations of the scattered (x,y) points to aid stability of Voronoi construction. This perturbation has no significant effect on the accuracy of the interpolated data.

Admissible Values (Boolean)True or False
Default ValueFalse
RemarksSet to True to force negative interpolated z values to zero.This may be useful to mask roundoff errors during interpolation when the surface passing through the points is known to be nonnegative.

Suppose you have a random set of (x,y,z) data points for some function z=f(x,y). How would you plot the 3D surface in Excel? the short answer is you can't unless you can resample the function at a uniform grid. If the function f(x,y) is unknown, re-sampling at a grid may not be an option. In this example, we will show how you can use GRIDXYZ to interpolate the scattered data set onto a uniform grid for easy plotting. To illustrate the concepts, we will sample the random set from a famous function: the Mexican hat function, a radially symmetric sinc function given by: fx,y=sinx2+y2x2+y2 which has a shape like a Mexican hat.

To generate the scattered data, we use Excel Rand() function to generate random values for x, and y in the interval [0 12]. To preserve the generated random numbers from continuously changing, we must copy them into a new range as numbers only. The table below shows our generated scattered (x,y) points and corresponding z values for the Mexican hat function using Excel's AutoFill feature.

3random xrandom yz values
Drag down to row 300

We have generated about three hundred points to obtain good coverage for the large [0 12] by [0 12] grid area we plan to use to be able to to show the Mexican hat function.
The steps to generate a grid in Excel are straight forward. we create a uniform row vector for the x-values and a uniform vertical vector for the y-values, as shown below. We chose to create a grid in increment of 0.4 from 0 to 12 for both x and y directions using AutoFill. Note how the x- and y-coordinates are arranged. the yellow shaded area represents the grid (x,y) points at which the z values will be found.


Now to interpolate the scattered (x,y,z) data onto the grid, we evaluate the array formula =GRIDXYZ(A3:B300, C3:C300, I3:AM3, H4:H33) in the yellow range. The first argument A3:B300 is the (x,y) values of the scattered data points, the 2nd argument C3:C300 is the corresponding z values, the 3rd argument I3:AM3 is the generated grid x values, and the 4th argument H4:H33 is the generated grid y values. Excel does the rest for us and correctly computes the interpolated z values at each grid location. The interpolated values are partially shown below.


To generate the surface plot in Excel, we simply highlight the yellow range and insert a surface plot. The plot is shown below and shows only one quarter of the radially symmetric Mexican hat function.

GRIDXYZ implements the natural neighbor interpolation algorithm.

  • Wikipedia, https://en.wikipedia.org/wiki/Natural_neighbor_interpolation.
Question or Comment? Email us:
support @ excel-works.com

ExceLab: Transforming Excel into a Calculus Power House

ExceLab functions and methods are protected by USA Patents 10628634, 10114812, 9892108 and 9286286.

© 2015-2023, ExcelWorks LLC
Boston, USA