hist — Create legacy center-based histograms for quick distribution plots and MATLAB hist workflows.
hist is the legacy histogram builtin that uses MATLAB hist semantics. The most important distinction from histogram is that when you pass a vector as the second argument, hist interprets that vector as bin centers rather than bin edges. In RunMat, hist remains useful for center-based legacy workflows, while histogram is the newer object-style histogram API with bin-edge semantics and handle-based property workflows.
How hist works
hist(data)uses a default number of bins based on the input size, following MATLAB-style legacy behavior.hist(data, v)interpretsvas bin centers, not bin edges. This is the key semantic difference fromhistogram.histis a plotting-style histogram command, whilehistogramreturns a first-class histogram object handle.- Normalization and bin-control workflows are supported, but the builtin should still be documented and used as the legacy center-based histogram path rather than as an alias of
histogram. - GPU-aware computation is used where supported, but semantics stay aligned with legacy MATLAB
histbehavior.
Examples
Create a default legacy histogram
data = randn(1, 1000);
hist(data);Pass explicit bin centers
data = randn(1, 500);
centers = -3:0.5:3;
hist(data, centers);Expected output:
% Here the second argument is interpreted as bin centers, not edgesCompare legacy hist semantics with modern histogram intent
data = randn(1, 300);
hist(data, -2:0.5:2);Expected output:
% Use histogram(...) instead when you want bin-edge semantics and an object handleFAQ
What's the actual difference between hist and histogram?⌄
The critical difference is how the second argument is interpreted. hist(data, v) treats v as bin centers. histogram(data, 'BinEdges', v) treats v as bin edges. Beyond that, histogram returns a handle object with properties you can query via get, while hist is a fire-and-forget plotting command.
When should I use hist instead of histogram?⌄
Use hist when you're porting legacy MATLAB code that relies on center-based binning or when you want a quick distribution plot without needing a handle object. For anything new—especially if you need normalization modes, bin-edge control, or programmatic access to bin counts—use histogram instead.
Related Plotting functions
More plotting resources
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.