RunMat
GitHub

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 surf works in 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.

Examples

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

Wave interference from 8 point sources

N = 300;
x = linspace(-10, 10, N);
y = linspace(-10, 10, N);
[X, Y] = meshgrid(single(x), single(y));

% Gaussian envelope — smoothly damps the surface toward the edges
envelope = exp(-(X.^2 + Y.^2) / 25);

for t = 1:80
    Z = zeros(N, N, 'single');

    % Superpose 8 wave sources equally spaced around a circle
    for k = 1:8
        a = 2 * pi * k / 8;
        cx = 6 * cos(a);
        cy = 6 * sin(a);
        r = sqrt((X - cx).^2 + (Y - cy).^2) + 0.1;

        Z = Z + sin(5 * r - t * 0.2 + k * 0.8) ./ (1 + r);
    end

    Z = Z .* envelope;
    surf(x, y, Z);
    colormap("jet");
    shading("interp");
    drawnow;
end

These functions work well alongside surf. Each page has runnable examples you can try in the browser.

bar, contour, contourf, hist, mesh, meshc, plot, scatter, scatter3, stairs, surfc

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how surf works, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat — free, no sign-up

Start running MATLAB code immediately in your browser.