hist — Render MATLAB-compatible histograms using automatic or user-specified bin counts.
hist(data, nbins) counts the number of observations that fall into equally spaced bins spanning the data range. When nbins is omitted, MATLAB (and RunMat) default to floor(sqrt(numel(data))) bins. The resulting frequencies are displayed as a bar chart.
How hist works in RunMat
- Inputs must be numeric vectors. Empty inputs return a figure with zero-height bins.
nbinsmay be provided as a numeric scalar or a vector of equally spaced bin centers. Non-positive or non-finite values raise MATLAB-style errors.- A
'BinEdges'name-value pair accepts a strictly increasing vector of edges (uniform or non-uniform). When the edges are evenly spaced the gpuArray path remains zero-copy; other cases fall back to the CPU implementation automatically. - Normalization can be supplied either as the second positional argument or via the
'Normalization'name-value pair. Supported values are"count","probability", and"pdf". - Single-precision gpuArray inputs stay on the device: bin counts are computed by a compute shader and bar vertices are emitted directly into the shared WebGPU context whenever the bins are uniform. Other cases gather automatically (full normalization semantics still apply in either path).
Example
data = randn(1, 1000);
hist(data, 20)Related functions to explore
These functions work well alongside hist. Each page has runnable examples you can try in the browser.
bar, contour, contourf, mesh, meshc, plot, scatter, scatter3, stairs, surf, surfc
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how hist works, line by line, in Rust.
- View hist.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.