File Exchange

image thumbnail

2D Histogram

version 1.0 (1.4 KB) by

Calculates and draws the 3D histogram of 2 Dimensional input data

14 Ratings



No License

function H = hist2d(D,Xn,Yn,[Xlo Xhi],[Ylo Yhi])

Calculates and draws the 3D histogram of 2 Dimensional input data D.

Counts number of points in the bins defined by
X = linspace(Xlo,Xhi,Xn) and
Y = linspace(Ylo,Yhi,Yn)

D must be a 2 column or 2 row matrix or an array of complex numbers

[Xlo Xhi],[Ylo Yhi] are optional and default to the min and max of
the input data
Xn and Yn are optional and default to 20

hist2d([randn(1,10000); randn(1,10000)])

Really just a copy of 2D Histogram, by Rey Patlolla, but with default arguments, optionally complex input and draws a 3D histogram.

Comments and Ratings (15)


Weijia Yang

Really useful. Thank you!


Liang (view profile)


Jochem (view profile)

Great function. Used it before discovering hist3.


Thomas (view profile)

This function works, but it is much slower than hist3 on large data sets. For instance, on two arrays of ~500,000 length, this function took ~30 s while hist3 took ~0.1 s.


David (view profile)

A nice, easy-to-use function; though I've just discovered that the statistics toolbox has a function hist3 with this functionality.


David (view profile)

Simple and useful!

Kamrul Hakim

Reda Boufatah

very good demonstration using hist

umair qureshi

fairly easy to understand and use !! hats off to u!!

Brian Liswell

Easy to implement. Grinds out fairly quickly on my PC.
The responses for the 2D Histogram entry say stuff about bugs - any clue what those are?

Know of any way to make a rectangular topped surface instead of angular surf?

Adama Ouattara

Good !

Aureli Soria-Frisch

General Tricky

Handy tool

MATLAB Release
MATLAB 7.2 (R2006a)

Inspired by: 2-Dimensional Histogram

Inspired: Fast 2D histogram calculation, createContour

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video