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, ...)
[counts, centers] = hist(X)
[counts, centers] = hist(X, bins)Inputs
X- Type
Any- Required
- Yes
- Description
- Input sample data.
bins- Type
Any- Required
- Yes
- Description
- Bin count scalar or explicit center vector.
normalization- Type
StringScalar- Required
- Yes
- Default
count- Description
- Normalization mode: count, probability, or pdf.
name_value- Type
Any- Required
- Variadic
- Description
- Name/value options and style properties.
name_value- Type
Any- Required
- Variadic
- Description
- Additional name/value options and style properties.
Returns
N- Type
NumericArray- Description
- Histogram bin counts.
centers- Type
NumericArray- Description
- Histogram bin centers.
Returned values from hist depend on how many outputs the caller requests.
Errors
RunMat:hist:InvalidArgument- When
- Histogram inputs, bins, normalization, weights, or style arguments are invalid.
- Message
hist: invalid argument
RunMat:hist:Internal- When
- Internal histogram rendering or device conversion fails.
- Message
hist: internal operation failed
RunMat:plotting:TooManyOutputs- When
- More than 2 output arguments are requested.
- Message
hist: too many output arguments
Behavior
hist(data) uses ten bins by default. Ordinary row and column vectors create one distribution; matrix columns use the existing per-column bin selection.
hist(data, v) interprets v as bin centers, not bin edges. This is the key semantic difference from histogram.
hist is a plotting-style histogram command, while histogram returns 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 hist behavior.
Rendering and residency
hist supports GPU-aware histogram computation where applicable, but it remains the legacy center-based histogram workflow rather than the object-based histogram API.
Declared source precision and class coverage
single
double
Coordinate broadcasting
none
Runtime contract and boundaries
Catalog default bindings retain the actual RuntimeContext and original rooted BuiltinArguments across parsing, provider readback, delegated calls and completion. Value-selected axes, properties and output counts remain Runtime decisions. Constructor results are host double graphics handles, not numerical GPU arrays; hist instead returns double counts/centres, plotyy up to three distinct handle outputs, and plotmatrix up to five.
Rendering is a fusion boundary and requires the installed graphics host/device. A direct compatible renderer route is not an elementwise or reduction provider kernel. Resident buffers retain their owning provider and existing export/error/completion protocol; an export, readback, allocation, cancellation or emission failure is an error, not permission to replay an attempted operation. Source data and renderer caches have distinct lifetimes. No new distributed chart implementation is declared.
The existing canonical CoordinateWork allocation policy refuses Managed calls before unowned chart scratch, metadata, readback or scene mutation. It checks captured cancellation generation and policy before publication and on completion; ingress failures are Never replay. This is an explicit missing finite owner, not an allocation estimate, algorithm completion or L25 closure. Provider-private allocations, renderer lifetime accounting, synchronous long geometry/copy cooperation, measured throughput and physical presentation remain independent qualification gates.
Native Single/Double/integer source ownership is distinguished from explicit binary64/f32 graphics conversion. The renderer does not promise exact wide-integer pixel positions. Logical, complex, sparse, scalar, vector, matrix, empty and higher-rank forms follow the identity-specific parser rather than a universal implicit cast. Sparse/complex rejection is not an integer not-applicable audit. Full MATLAB properties, browser/native parity and empty-shape conformance are not inferred from migration or historical test references.
Supported representations and remaining forms
The legacy API returns zero, one or two requested outputs: double counts and optionally centres, while retaining the existing plotting behavior. The default is ten bins, not a sample-size formula. A positional vector supplies centres, a scalar supplies a validated count. Integer sample/centre and modern option forms retain their distinct existing compatibility extensions; integer count controls are structural. Modern BinEdges/NumBins/BinWidth/BinLimits/BinMethod/Weights/Normalization controls retain their existing exclusivity and validation rules.
Ordinary 1-by-N and N-by-1 vectors now use one distribution and return row counts/centres. Matrix columns still form separate grouped distributions; automatic/count bins are selected per column, while explicit/shared controls retain the old common-bin owner. No new N-D or empty geometry rule is introduced by that bounded vector correction. Probability and PDF weights use the existing per-column totals and widths.
The eligible resident floating-vector path preserves the existing typed GPU histogram preparation states: complete chart, prepared host bins, or required host statistics. Continuing already successful preparation is not retry permission: after-effect failures remain terminal. Unsupported styling or pre-effect inapplicability retains the existing owner-aware CPU route, not a provider-name heuristic. Finite workspace/renderer completion and CPU long-loop cooperation remain unclosed. Bar getters do not expose count vectors; examples separately assert the real returned numerical counts and retained Runtime fixtures inspect chart data.
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 centres; histogram(data, 'BinEdges', v) treats v as bin edges. histogram returns a chart handle with get/set properties. hist is the legacy plotting/count API: one requested output returns double counts and two return counts and centres; it is not a histogram object alias.
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
2D Charts
area · bar · errorbar · heatmap · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · autumn · axes · barh · bone · caxis · cla · clf · clim · colorcube · colororder · cool · copper · copyobj · cylinder · daspect · datacursormode · dataTipTextRow · drawnow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · gray · groot · hgload · hgsave · hidden · histogram2 · hold · hot · inferno · isgraphics · ishandle · jet · line · lines · linkaxes · magma · openfig · opengl · pan · parula · patch · pink · plasma · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · spring · stackedplot · subtitle · summer · suptitle · text · textscatter · textscatter3 · triplot · turbo · viridis · waitbar · winter · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
More plotting resources
Source you can read
Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.