Qu

meshgrid

Builtin index · Core maths

result = meshgrid(x, y)

Input: x, y · Output: result

What it is

The two coordinate matrices a surface or contour needs, from two axis vectors x (length nx) and y (length ny).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = meshgrid(x, y)
x vectornot documented yet
y vectornot documented yet
result Record, Mat, or vector
Returns a Record with fields x and y, each an ny×nx Mat: .x repeats the x vector down every row, .y repeats the y vector across every column, so (.x[j,i], .y[j,i]) is the grid point for x[i], y[j].

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

g = meshgrid([1, 2, 3], [1, 2])
print(g.x)   # x-coordinate at every grid point

print(g.y)   # y-coordinate at every grid point


M = [1, 2, 3; 4, 5, 6]
print(ones_like(M))
print(zeros_like(M))
print("row_mean={row_mean(M)}  row_sum={row_sum(M)}")
output
[1, 2, 3; 1, 2, 3]
[1, 1, 1; 2, 2, 2]
[1, 1, 1; 1, 1, 1]
[0, 0, 0; 0, 0, 0]
row_mean=[2; 5]  row_sum=[6; 15]

from core-math

f = logspace(0, 3, 200)
mag = 1 ./ sqrt(1 + (f / 100) .^ 2)
semilogx(f, mag)
figure()
x = 1 to 50
semilogy(x, exp(0.1 * x))
figure()
loglog(f, mag)
figure()
samples = randn(500, seed = 2)
hist(samples, bins = 15)
figure()
g = meshgrid(-3 to 3 step 0.2, -3 to 3 step 0.2)
Z = sin(sqrt(g.x .^ 2 + g.y .^ 2))
contour(g.x, g.y, Z)
figure()
contourf(g.x, g.y, Z)
figure()
tbl = table(a = randn(30, seed = 3), b = randn(30, seed = 4), c = randn(30, seed = 5))
corr_heatmap(tbl)
figure()
corrplot(tbl)
output
· hist: figure 31 (500 points, 15 bins)
a, a: 1 1 a, b: 0.048 0.048 a, c: 0.051 0.051 b, a: 0.048 0.048 b, b: 1 1 b, c: -0.117 -0.117 c, a: 0.051 0.051 c, b: -0.117 -0.117 c, c: 1 1 a b c a b c

from plotting

How it works

meshgrid(x, y) -- the two coordinate matrices MATLAB and NumPy build before evaluating a field over a grid. Returned as a record with .x and .y rather than as two values, because Qu has no multi-return destructuring; it is the same shape eig already uses for its two outputs. Both matrices are y.len() rows by x.len() columns, which is meshgrid's convention and not ndgrid's transpose.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.