RunMat
GitHub

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) 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

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 · 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 · suptitle · xline · yline

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.

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.

Getting started · Benchmarks · Pricing

Try RunMat for free

Write code or describe what you want to compute. The sandbox is free, no account required.