Click or drag to resize
Accord.NET (logo)

MatrixMeshGridT Method

Generates a 2-D mesh grid from two vectors a and b, generating two matrices len(a) x len(b) with all all possible combinations of values between the two vectors. This method is analogous to MATLAB/Octave's meshgrid function.

Namespace:  Accord.Math
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public static Tuple<T[,], T[,]> MeshGrid<T>(
	this T[] x,
	T[] y
)
Request Example View Source

Parameters

x
Type: T
y
Type: T

Type Parameters

T

Return Value

Type: TupleT, T
A tuple containing two matrices: the first containing values for the x-coordinates and the second for the y-coordinates.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Examples
// The MeshGrid method generates two matrices that can be // used to generate all possible (x,y) pairs between two // vector of points. For example, let's suppose we have // the values: // double[] a = { 1, 2, 3 }; double[] b = { 4, 5, 6 }; // We can create a grid var grid = a.MeshGrid(b); // get the x-axis values // | 1 1 1 | double[,] x = grid.Item1; // x = | 2 2 2 | // | 3 3 3 | // get the y-axis values // | 4 5 6 | double[,] y = grid.Item2; // y = | 4 5 6 | // | 4 5 6 | // we can either use those matrices separately (such as for plotting // purposes) or we can also generate a grid of all the (x,y) pairs as // double[,][] xy = x.ApplyWithIndex((v, i, j) => new[] { x[i, j], y[i, j] }); // The result will be // // | (1, 4) (1, 5) (1, 6) | // xy = | (2, 4) (2, 5) (2, 6) | // | (3, 4) (3, 5) (3, 6) |
See Also