hist — Create legacy center-based histograms in MATLAB and RunMat.
hist creates legacy histograms using bin-center semantics. When the second argument is a vector, it is interpreted as bin centers rather than bin edges, consistent with MATLAB behavior.
Syntax
N = hist(X)
N = hist(X, bins)
N = hist(X, normalization)
N = hist(X, Name, Value, ...)
N = hist(X, bins, Name, Value, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
X | Any | Yes | — | Input sample data. |
bins | Any | Yes | — | Bin count scalar or explicit center vector. |
normalization | StringScalar | Yes | count | Normalization mode: count, probability, or pdf. |
name_value | Any | Variadic | — | Name/value options and style properties. |
name_value | Any | Variadic | — | Additional name/value options and style properties. |
Returns
| Name | Type | Description |
|---|---|---|
N | NumericArray | Histogram bin counts. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:hist:InvalidArgument | Histogram inputs, bins, normalization, weights, or style arguments are invalid. | hist: invalid argument |
RunMat:hist:Internal | Internal histogram rendering or device conversion fails. | hist: internal operation failed |
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 handleUsing hist with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how hist changes the result.
Run a small hist example, explain the result, then change one input and compare the output.
FAQ
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 is executed, line by line, in Rust.
- View the source for hist in Rust on GitHub
- Learn how the RunMat 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 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.