RunMat
GitHub

stairs — Create staircase line plots for sampled or piecewise-constant data with MATLAB-compatible stairs syntax.

stairs creates staircase-style line plots from y or paired x, y inputs and returns a graphics handle. It supports MATLAB-compatible call forms and shared plotting property updates.

Syntax

h = stairs(Y)
h = stairs(X, Y)
h = stairs(X, Y, LineSpec)
h = stairs(X, Y, Name, Value, ...)
h = stairs(ax, Y)
h = stairs(ax, X, Y)
h = stairs(ax, X, Y, LineSpec)
h = stairs(ax, X, Y, Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
YNumericArrayYesY samples. X defaults to 1:numel(Y).
XNumericArrayYesX samples.
YNumericArrayYesY samples.
lineSpecStyleSpecYesLine style shorthand such as '--r'.
propsAnyVariadicName/value style properties.
axAxesHandleYesTarget axes handle.

Returns

NameTypeDescription
hNumericScalarHandle to the rendered stairs plot.

Errors

IdentifierWhenMessage
RunMat:stairs:InvalidArgumentInput data, axes targeting, or style arguments are invalid.stairs: invalid argument
RunMat:stairs:InternalInternal plot construction or rendering fails unexpectedly.stairs: internal operation failed

How stairs works

  • stairs(y) uses implicit x-values 1:n, while stairs(x, y) uses explicit paired coordinates.
  • The returned value is a plot handle that works with get and set.
  • Marker styling and display names can be updated through the same handle/property system used by line plots.
  • Step-plot rendering is subplot-local and respects current axes state just like plot and scatter.
  • GPU-backed geometry is preferred when exported buffers and the shared plotting device are available.

Examples

Plot a sampled staircase signal

t = 0:5;
stairs(t, cumsum([1 -1 2 -2 1 0]));

Use MATLAB-style y-only shorthand

stairs([3 1 4 1 5 9]);

Style a stairs object and label it for the legend

h = stairs(0:4, [1 2 2 3 5]);
set(h, 'Color', 'm', 'LineWidth', 2, 'DisplayName', 'sampled signal');
legend;

Piecewise-constant step response

t = 0:0.5:10;
y = 1 - exp(-0.5*t);

h = stairs(t, y);
set(h, 'LineWidth', 2);
title('First-Order Step Response');
xlabel('Time (s)');
ylabel('Output');
grid on;
Expected output:
Piecewise-constant step response

Using stairs with coding agents

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

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

FAQ

When should I use stairs instead of plot?

stairs draws piecewise-constant steps between points, while plot linearly interpolates. Use stairs when your data is held constant between samples—DAC output, quantized signals, sample-and-hold systems, or any situation where the value doesn't change smoothly between observations.

How do I visualize a digital signal with stairs?

Pass your time vector and signal values directly. The staircase rendering naturally represents digital/discrete-time signals where values snap between levels.

t = 0:0.01:1;
signal = double(square(2*pi*5*t) > 0);
stairs(t, signal);
ylim([-0.2 1.2]);

This avoids the misleading diagonal transitions that plot would draw between high and low states.

Can I add markers to a stairs plot?

Yes. Set the 'Marker' property on the returned handle, just like you would with plot.

h = stairs(0:4, [1 3 2 4 1]);
set(h, 'Marker', 'o', 'MarkerSize', 6);

Markers appear at each data point (the step corners), not along the flat segments.

2D Charts

area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stem

3D & Surface

contour · contour3 · contourf · mesh · meshc · plot3 · quiver · scatter3 · surf · surfc

Images

image · imagesc · imshow

Axes & Layout

axis · box · grid · sgtitle · subplot · title · view · zlabel

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

cla · clf · figure · fill3 · hold · patch · print · suptitle · xline · yline

More plotting resources

Open-source implementation

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

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.

Getting started · Benchmarks · Pricing

Download RunMat

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