mesh — Create wireframe surface plots in MATLAB and RunMat.
mesh creates wireframe surface plots from vector axes or meshgrid-style coordinates plus height data. Handle behavior and axis integration follow MATLAB semantics.
Syntax
h = mesh(Z)
h = mesh(X, Y, Z)
h = mesh(Z, Name, Value, ...)
h = mesh(X, Y, Z, Name, Value, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
Z | NumericArray | Yes | — | Surface height grid. |
X | NumericArray | Yes | — | X axis vector/meshgrid matrix matching Z columns. |
Y | NumericArray | Yes | — | Y axis vector/meshgrid matrix matching Z rows. |
props | Any | Variadic | — | Name/value surface style options. |
Returns
| Name | Type | Description |
|---|---|---|
h | NumericScalar | Handle to the rendered mesh surface. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:mesh:InvalidArgument | Surface input arrays or style name/value arguments are invalid. | mesh: invalid argument |
RunMat:mesh:Internal | Internal surface generation/render preparation fails unexpectedly. | mesh: internal operation failed |
How mesh works
mesh(Z)uses implicit axes, whilemesh(X, Y, Z)accepts vector axes or meshgrid-style coordinate matrices.- The builtin returns a surface handle, so mesh plots can still be inspected through the graphics-object system.
meshis the wireframe-oriented companion tosurf; for combined wireframe plus contour overlays, usemeshc.- RunMat uses the shared surface pipeline for mesh rendering, so view, z-axis labeling, and subplot-local state behave consistently across the surface family.
- GPU-backed rendering is preferred when the plotting device can consume exported buffers directly.
Examples
Create a wireframe mesh from a height field
[X, Y] = meshgrid(linspace(-2, 2, 60), linspace(-2, 2, 60));
Z = sin(X.^2 + Y.^2);
mesh(X, Y, Z);Compare wireframe presentation with subplot-local state
subplot(1, 2, 1);
[X, Y] = meshgrid(linspace(-2, 2, 40), linspace(-2, 2, 40));
Z = cos(X) .* sin(Y);
mesh(X, Y, Z);
view(3);
subplot(1, 2, 2);
surf(X, Y, Z);
view(3);Inspect the returned surface handle from mesh
[X, Y] = meshgrid(1:20, 1:20);
Z = X + Y;
h = mesh(X, Y, Z);
get(h, 'Type')Expected output:
ans =
'surface'Saddle surface showing grid structure
[X, Y] = meshgrid(linspace(-3, 3, 60), linspace(-3, 3, 60));
Z = X.^2 - Y.^2;
mesh(X, Y, Z);
colormap('jet');
colorbar;
title('Hyperbolic Paraboloid');
xlabel('x');
ylabel('y');
zlabel('z = x^2 - y^2');
view(40, 30);
Using mesh with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how mesh changes the result.
Run a small mesh example, explain the result, then change one input and compare the output.
FAQ
Can I get a filled surface instead of wireframe?⌄
That's what surf is for. mesh draws only the grid lines with transparent faces, while surf fills the faces with colormap-derived colors. If you want the wireframe look but with partial fill, there's no built-in blend — use surf with a low alpha or switch to mesh and accept the wireframe.
How do I combine a mesh with contour lines underneath?⌄
Use meshc instead of mesh. It draws the same wireframe surface but projects contour lines onto the base plane automatically.
[X, Y] = meshgrid(linspace(-2, 2, 50));
Z = sin(X.^2 + Y.^2);
meshc(X, Y, Z);Can I control transparency on a mesh plot?⌄
Mesh plots don't have filled faces to make transparent — the faces are already open. If you need a semi-transparent surface, use surf and set the FaceAlpha property on the returned handle. The wireframe edges on mesh are always fully opaque.
Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how mesh is executed, line by line, in Rust.
- View the source for mesh in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.