MeshGrid.jl
is a simple Julia module that provides functionality similar to MATLAB's meshgrid
function. It generates coordinate matrices from vectors or ranges, which are useful for evaluating functions over a grid in two or three dimensions.
To install MeshGrid.jl
, use the following command in the Julia REPL:
using Pkg
Pkg.add("MeshGrid")
These examples illustrate how MeshGrid.jl
can handle different data types and mixed types. This flexibility makes it easier to translate MATLAB code into Julia, providing a familiar interface for those transitioning from MATLAB to Julia. Note that the element data type of the output grid will be the promotion of the input element data types.
x = -1:1:1
y = -1:0.5:1
X, Y = meshgrid(x, y)
x = 1:3 # integer range
y = [1.0, 2.5, 4.0] # Float vector
X, Y = meshgrid(x, y) # elements are promoted to Float64
x = 1:3 # integer range
y = [1.0, 2.5, 4.0] # float vector
z = ["alice", "bob"] # string vector
X, Y, Z = meshgrid(x, y, z) # elements are promoted to Any