RunMat
GitHub

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

NameTypeRequiredDefaultDescription
XAnyYesInput sample data.
binsAnyYesBin count scalar or explicit center vector.
normalizationStringScalarYescountNormalization mode: count, probability, or pdf.
name_valueAnyVariadicName/value options and style properties.
name_valueAnyVariadicAdditional name/value options and style properties.

Returns

NameTypeDescription
NNumericArrayHistogram bin counts.

Errors

IdentifierWhenMessage
RunMat:hist:InvalidArgumentHistogram inputs, bins, normalization, weights, or style arguments are invalid.hist: invalid argument
RunMat:hist:InternalInternal 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) 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.

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 edges

Compare 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 handle

Using 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.

2D Charts

area · bar · errorbar · heatmap · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem

3D & Surface

contour · contour3 · contourf · mesh · meshc · plot3 · quiver · scatter3 · surf · surfc

Images

image · imagesc · imshow

Axes & Layout

axis · box · grid · sgtitle · subplot · title · view · zlabel

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

cla · clf · figure · fill3 · hold · patch · print · suptitle · xline · yline

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.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.