ndgridCreating grid points for evaluating multivariate functions
[X1, X2, ..., Xn] = ndgrid(x)x should be a vector of numeric values. Otherwise, it will be first reshaped to a vector.X1, X2, ..., Xn of identical sizes, which can be used to evaluate a function of n variables.x is empty.[X1,X2, ..., Xn] = ndgrid(x1, x2, ..., xn)x1, x2 and xn should be vectors of numeric values. If any of them is not a vector, it will be first reshaped to a vector.X1, X2, ..., Xn of identical sizes, which can be used to evaluate a function of n variables.x1, x2, ..., xn is empty.[x,y,z] = ndgrid(1:3)
f = x.^2 + y.^2 + z.^2
x(:, :, 1) =
1.0000 1.0000 1.0000
2.0000 2.0000 2.0000
3.0000 3.0000 3.0000
x(:, :, 2) =
1.0000 1.0000 1.0000
2.0000 2.0000 2.0000
3.0000 3.0000 3.0000
x(:, :, 3) =
1.0000 1.0000 1.0000
2.0000 2.0000 2.0000
3.0000 3.0000 3.0000
y(:, :, 1) =
1.0000 2.0000 3.0000
1.0000 2.0000 3.0000
1.0000 2.0000 3.0000
y(:, :, 2) =
1.0000 2.0000 3.0000
1.0000 2.0000 3.0000
1.0000 2.0000 3.0000
y(:, :, 3) =
1.0000 2.0000 3.0000
1.0000 2.0000 3.0000
1.0000 2.0000 3.0000
z(:, :, 1) =
1.0000 1.0000 1.0000
1.0000 1.0000 1.0000
1.0000 1.0000 1.0000
z(:, :, 2) =
2.0000 2.0000 2.0000
2.0000 2.0000 2.0000
2.0000 2.0000 2.0000
z(:, :, 3) =
3.0000 3.0000 3.0000
3.0000 3.0000 3.0000
3.0000 3.0000 3.0000
f(:, :, 1) =
3.0000 6.0000 11.000
6.0000 9.0000 14.000
11.000 14.000 19.000
f(:, :, 2) =
6.0000 9.0000 14.000
9.0000 12.000 17.000
14.000 17.000 22.000
f(:, :, 3) =
11.000 14.000 19.000
14.000 17.000 22.000
19.000 22.000 27.000
[x,y,z] = ndgrid(1:4, 5:7, 8:11)
f = x.^2 + y.^2 + z.^2
x(:, :, 1) =
1.0000 1.0000 1.0000
2.0000 2.0000 2.0000
3.0000 3.0000 3.0000
4.0000 4.0000 4.0000
x(:, :, 2) =
1.0000 1.0000 1.0000
2.0000 2.0000 2.0000
3.0000 3.0000 3.0000
4.0000 4.0000 4.0000
x(:, :, 3) =
1.0000 1.0000 1.0000
2.0000 2.0000 2.0000
3.0000 3.0000 3.0000
4.0000 4.0000 4.0000
x(:, :, 4) =
1.0000 1.0000 1.0000
2.0000 2.0000 2.0000
3.0000 3.0000 3.0000
4.0000 4.0000 4.0000
y(:, :, 1) =
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
y(:, :, 2) =
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
y(:, :, 3) =
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
y(:, :, 4) =
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
5.0000 6.0000 7.0000
z(:, :, 1) =
8.0000 8.0000 8.0000
8.0000 8.0000 8.0000
8.0000 8.0000 8.0000
8.0000 8.0000 8.0000
z(:, :, 2) =
9.0000 9.0000 9.0000
9.0000 9.0000 9.0000
9.0000 9.0000 9.0000
9.0000 9.0000 9.0000
z(:, :, 3) =
10.000 10.000 10.000
10.000 10.000 10.000
10.000 10.000 10.000
10.000 10.000 10.000
z(:, :, 4) =
11.000 11.000 11.000
11.000 11.000 11.000
11.000 11.000 11.000
11.000 11.000 11.000
f(:, :, 1) =
90.000 101.00 114.00
93.000 104.00 117.00
98.000 109.00 122.00
105.00 116.00 129.00
f(:, :, 2) =
107.00 118.00 131.00
110.00 121.00 134.00
115.00 126.00 139.00
122.00 133.00 146.00
f(:, :, 3) =
126.00 137.00 150.00
129.00 140.00 153.00
134.00 145.00 158.00
141.00 152.00 165.00
f(:, :, 4) =
147.00 158.00 171.00
150.00 161.00 174.00
155.00 166.00 179.00
162.00 173.00 186.00