stairs — Create step plots for sampled signals, piecewise-constant data, and MATLAB stairs workflows.
stairs creates staircase-style line plots for sampled or piecewise-constant data. In RunMat it returns a plot handle, supports MATLAB stairs(y) and stairs(x, y) style workflows, and reuses the shared line/marker property model so step plots behave consistently with the rest of the plotting stack.
How stairs works
stairs(y)uses implicit x-values1:n, whilestairs(x, y)uses explicit paired coordinates.- The returned value is a plot handle that works with
getandset. - 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
plotandscatter. - 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;
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.
Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how stairs works, line by line, in Rust.
- View stairs.rs on GitHub
- Learn how the 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 — 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.