RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.2, Nov 26, 2026 ·

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • colon
    • createArray
    • empty
    • eye
    • false
    • full
    • inf
    • int16.empty
    • int32.empty
    • int64.empty
    • int8.empty
    • linspace
    • logspace
    • magic
    • meshgrid
    • nan
    • ndgrid
    • nonzeros
    • ones
    • peaks
    • rand
    • randi
    • randn
    • randperm
    • range
    • sparse
    • spdiags
    • speye
    • spones
    • sprand
    • true
    • uint16.empty
    • uint32.empty
    • uint64.empty
    • uint8.empty
    • zeros

meshgrid — Generate coordinate grids in MATLAB and RunMat.

meshgrid expands coordinate vectors into 2-D or 3-D coordinate arrays spanning rectangular grids. Output ordering and dimensional replication follow MATLAB semantics.

Syntax

[X,Y] = meshgrid(x)
[X,Y] = meshgrid(x, y)
[X,Y,Z] = meshgrid(x, y, z)
[X,Y] = meshgrid(x, "like", prototype)
[X,Y] = meshgrid(x, y, "like", prototype)
[X,Y,Z] = meshgrid(x, y, z, "like", prototype)

Inputs

x
Type
NumericArray
Required
Yes
Description
X-axis vector.
y
Type
NumericArray
Required
Yes
Description
Y-axis vector.
z
Type
NumericArray
Required
No
Description
Z-axis vector.
like_kw
Type
StringScalar
Required
Yes
Default
"like"
Description
Like keyword.
prototype
Type
LikePrototype
Required
Yes
Description
Prototype controlling class/device residency.
NameTypeRequiredDefaultDescription
xNumericArrayYes—X-axis vector.
yNumericArrayYes—Y-axis vector.
zNumericArrayNo—Z-axis vector.
like_kwStringScalarYes"like"Like keyword.
prototypeLikePrototypeYes—Prototype controlling class/device residency.

Returns

X
Type
NumericArray
Description
Grid coordinates along X-axis.
Y
Type
NumericArray
Description
Grid coordinates along Y-axis.
Z
Type
NumericArray
Description
Grid coordinates along Z-axis.
NameTypeDescription
XNumericArrayGrid coordinates along X-axis.
YNumericArrayGrid coordinates along Y-axis.
ZNumericArrayGrid coordinates along Z-axis.

Returned values from meshgrid depend on how many outputs the caller requests.

Errors

—
When
No axis vectors are provided.
Message
meshgrid: at least one input vector is required
—
When
More than three axis vectors are provided.
Message
meshgrid: expected at most three input vectors
—
When
The 'like' keyword is provided without a prototype argument.
Message
meshgrid: expected prototype after 'like'
IdentifierWhenMessage
—No axis vectors are provided.meshgrid: at least one input vector is required
—More than three axis vectors are provided.meshgrid: expected at most three input vectors
—The 'like' keyword is provided without a prototype argument.meshgrid: expected prototype after 'like'
—The 'like' keyword is provided multiple times.meshgrid: multiple 'like' specifications are not supported
—The 'like' keyword is in an invalid position or not final.meshgrid: 'like' must be the final argument
—A trailing option string is not recognized.meshgrid: unrecognised option
—Axis inputs are non-numeric or non-vector shapes.meshgrid: input argument must be numeric vector data
—The 'like' prototype is unsupported.meshgrid: prototypes must be numeric arrays
—Requested outputs exceed available outputs for provided axes.meshgrid: supports at most two outputs for 2-axis inputs and three for 3-axis inputs
—A third output is requested without supplying a Z-axis vector.meshgrid: third output requested but no Z vector was supplied
—Complex axis values cannot be represented in requested real output class.meshgrid: cannot represent complex values in a real output

Behavior

meshgrid(x) is shorthand for [X, Y] = meshgrid(x, x). It produces square 2-D grids.

meshgrid(x, y) yields X of size length(y) × length(x) with rows copied from x, and Y of the same size with columns copied from y.

meshgrid(x, y, z) returns three outputs sized length(y) × length(x) × length(z), enabling 3-D volume visualisation.

Input vectors may be row or column vectors (or even scalars). Empty vectors propagate to empty grids of matching shape.

In runmat compatibility mode, complex axes are a RunMat extension and produce complex grids that preserve their values and precision.

Documented single and double GPU vectors keep outputs resident when an acceleration provider is active. Explicit real-integer gpuArray axes reject; automatically resident real-integer axes gather transparently and produce exact host grids. Paired-complex integer axes are a RunMat extension and preserve exact resident output.

In runmat compatibility mode, the RunMat-only 'like', prototype selector matches both residency and numeric class. Ordinary MATLAB-compatible calls preserve each corresponding input axis class, including all eight integer classes.

Execution and residency

You usually do not need to wrap vectors with gpuArray manually. When the active acceleration provider supports uploads, RunMat keeps real and complex-interleaved outputs on the GPU. In runmat compatibility mode, the RunMat-only 'like', gpuArray(...) selector can request GPU output even when every input axis is host-resident.

For admitted real resident vector axes on the same exact provider, RunMat can reshape and replicate the axes directly on that device. When that direct route is not eligible, RunMat materialises grids on the host and restores them to the requesting GPU owner when the provider can represent the output class. Native real and paired-complex storage is preserved exactly; an operational failure during the direct route is an error, not a request to replay the work on the host.

Examples

Generating a square 2-D grid from one vector

x = -2:2;
[X, Y] = meshgrid(x)

Expected output:

X =
    -2    -1     0     1     2
    -2    -1     0     1     2
    -2    -1     0     1     2
    -2    -1     0     1     2
    -2    -1     0     1     2

Building a rectangular grid from two different vectors

x = [0 0.5 1.0];
y = [10 20];
[X, Y] = meshgrid(x, y)

Expected output:

X =
         0    0.5000    1.0000
         0    0.5000    1.0000

Y =
    10    10    10
    20    20    20

Creating a volumetric grid for 3-D plotting

u = -1:1;
v = 2:4;
w = linspace(0, 1, 5);
[U, V, W] = meshgrid(u, v, w);
size(U)

Expected output:

ans =
     3     3     5

Matching an existing GPU prototype

gx = gpuArray(single(linspace(-pi, pi, 4)));
gy = gpuArray(single([-1 0 1]));
[Xg, Yg] = meshgrid(gx, gy)

Matching grid storage to a prototype

proto = gpuArray.zeros(1, 1, 'double');
angles = linspace(0, 2*pi, 8);
radius = [0 1 2];
[X, Y] = meshgrid(angles, radius, 'like', proto)

Creating grids from complex axes

z = [1+1i, 2+4i];
[Zx, Zy] = meshgrid(z)

Using meshgrid with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how meshgrid changes the result.

Run a small meshgrid example, explain the result, then change one input and compare the output.

FAQ

How many inputs can meshgrid accept?⌄

One, two, or three numeric vectors. Use three inputs when you need volumetric (3-D) grids.

Can I request three outputs with only one or two inputs?⌄

No. RunMat follows MATLAB and requires three input vectors when three outputs are requested.

Do row or column vectors behave differently?⌄

No. Any vector shape (row, column, or scalar) is accepted. RunMat treats the linearised data identically and replicates it along the appropriate axes.

What happens with empty vectors?⌄

Empty inputs propagate to empty outputs. For example, meshgrid([], 1:3) returns 0×3 grids for both outputs.

Can I use integer vectors?⌄

Yes. Each output preserves the class of its corresponding input axis, including exact values from all eight integer classes.

Does meshgrid support complex numbers?⌄

Complex axes are a RunMat-only extension available in runmat compatibility mode. Their imaginary components and precision propagate to complex outputs, including exact paired-integer components and complex-interleaved GPU output when a provider is active.

What does 'like' do?⌄

It is a RunMat-only selector available in runmat compatibility mode. It matches the numeric class and residency of the prototype array; ordinary MATLAB-compatible code controls class and residency through the input axes.

How can providers avoid the host fall-back?⌄

For supported real resident vector axes on one device, RunMat uses the owning provider's reshape and repmat hooks to construct resident grids. Other admitted forms use host construction, restoring GPU output to the requesting owner when applicable and supported. An operational provider-hook failure is returned as an error.

Is the output always dense?⌄

Yes. meshgrid produces dense arrays. Use ndgrid when you need permuted axes or higher-dimensional grids beyond three inputs.

What error do I get if I omit all inputs?⌄

RunMat raises the MATLAB-compatible error meshgrid: at least one input vector is required.

Related Array functions

Creation

colon · createArray · empty · eye · false · full · inf · int16.empty · int32.empty · int64.empty · int8.empty · linspace · logspace · magic · nan · ndgrid · nonzeros · ones · peaks · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · uint16.empty · uint32.empty · uint64.empty · uint8.empty · zeros

Accumulation

accumarray

Sorting Sets

argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique

Shape

blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · shiftdim · squeeze · toeplitz · tril · triu · vertcat

Combinatorics

combinations · nchoosek · perms

Binning

discretize

Indexing

find · ind2sub · sub2ind

Grouping

findgroups · groupcounts · grp2idx · splitapply

Introspection

height · iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · numel · size · width

Source you can read

Every RunMat function's source is public. Read exactly how meshgrid is executed, line by line, in Rust.

  • View the source for meshgrid in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Behavior
  • Execution and residency
  • Examples
  • Generating a square 2-D grid from one vector
  • Building a rectangular grid from two different vectors
  • Creating a volumetric grid for 3-D plotting
  • Matching an existing GPU prototype
  • Matching grid storage to a prototype
  • Creating grids from complex axes
  • Using meshgrid with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Accumulation
  • Sorting Sets
  • Shape
  • Combinatorics
  • Binning
  • Indexing
  • Grouping
  • Introspection
  • Source you can read
  • About RunMat