# 14 Matrix Conversion and Gridding

Origin 9.0 introduced 3D surface or contour plotting directly from XYZ worksheet columns or from a Virtual Matrix. Prior to that release, creating these plot types in Origin required gridding of worksheet data. The resulting matrix of Z values was used to create the contour or 3D surface. This section explains Origin's gridding options.

There are two basic types of worksheet to matrix conversions in Origin:

• Direct Conversion. One common workbook data arrangement -- particularly for Excel users -- is for X and Y measurements to be stored in the first row and first column of the worksheet, with Z values stored in cells at the intersection of each XY data pair.
• XYZ Gridding. Gridding methods convert XYZ data into a matrix using a selected algorithm.
• XYZ Log Gridding. Calculate logarithmic values for X and Y first, and then perform XYZ Gridding.
• Expand. This method is used when an ASCII (or other) import produces multiple Worksheet rows for each single matrix row.

Direct Conversion, then, merely copies the Z data contained in the worksheet to an Origin matrix -- either directly or while transposing the data -- much as if you had done a cut and paste operation.

The XYZ Gridding and XYZ Log Gridding operations, on the other hand, are more complex. An Origin matrix is a rectangular array of Z values whose columns are linearly mapped to X values and whose rows are linearly mapped to Y values. If the original worksheet XYZ data is regularly spaced in both the X and Y dimensions, we convert the data into a matrix using the Regular gridding method. If the data are not regularly-spaced in the X and Y dimensions, one of several Random gridding methods must be used.

For random data gridding methods, we can describe the problem mathematically: Given a set of irregularly distributed points (xi, yi, zi), we construct a function F(x, y) which interpolates the data as F(xi, yi)=zi. In the XY plane, the data points must be distinct (multiple Z values for a given XY pair, are not allowed -- see Note 1). The constructed surface is continuous and has continuous first derivatives.

When interpolating, data points nearer the estimated grid point are given greater weight. Both global and local strategies are used when defining the grid. Global algorithms use all data points to estimate each grid point, while local strategies use only those XY data in close proximity to the estimated grid point. Gridding results will, therefore, differ somewhat, depending upon the algorithm used. Also, because a global algorithm must incorporate information from more XY pairs, it is, naturally, more computationally intensive (for a relative speed comparison, see XYZ Gridding Methods).

 Note 1: Collinear data in a set is not allowed because it does not define a surface, so collinear points need to be removed. Also, multiple z values at a specific x,y point may have multiple options for determining a composite z value.
 Note 2: The Origin matrixbook has two heading view modes: Row/Column (View: Show Column/Row) and Show X/Y (View: Show X/Y). When you are in Row/Column mode, the matrix row and column index numbers display in the row and column headings. When you are in X/Y mode, the matrix X and Y values display in the row and column headings.  Topics covered in this section: