RunMat
GitHub

View all functions

CategoryPlotting
GPUYes

surf — Render MATLAB-compatible 3-D surface plots.

surf(X, Y, Z) draws a shaded surface where X and Y provide axis coordinates and Z provides heights. RunMat accepts either (1) vector axes X and Y plus a grid Z with numel(X) * numel(Y) elements stored in column-major order, or (2) meshgrid-style coordinate matrices X/Y that match the shape of Z. When Z is a single-precision gpuArray and the shared WebGPU renderer is active, the surface geometry stays on the device and feeds a compute shader that emits renderer-ready vertices.

How does the surf function behave in MATLAB / RunMat?

  • Axis vectors must be non-empty and Z must contain exactly length(X) * length(Y) elements.
  • Single-precision gpuArray height maps stream directly into the renderer; other precisions gather to host memory before plotting.
  • Surfaces default to the Parula colormap with smooth shading and lighting enabled.

Example of using surf in MATLAB / RunMat

x = linspace(-2, 2, 50);
y = linspace(-2, 2, 50);
z = meshgrid(x, y);
surf(x, y, sin(x)' * cos(y))

Source & Feedback