View License

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

» Watch video

Highlights from
N-Dimensional Histogram Count

Be the first to rate this file! 6 Downloads (last 30 days) File Size: 2.46 KB File ID: #29435 Version: 1.5

N-Dimensional Histogram Count


Mathew (view profile)


17 Nov 2010 (Updated )

Bins the elements of n matrices into an n-dimensional histogram.

| Watch this File

File Information

HISTCND is similar to HISTC, but creates a histogram with any number of dimensions.


where N is a histogram count with dimensions
         length(XEDGES) x length(YEDGES) x length(ZEDGES) ...

If XEDGES, YEDGES, etc. are monotonically increasing and non-NaN, a data point is assigned to bin N(i,j,k,...) if
   XEDGES(i) <= X < XEDGES(i+1)
   YEDGES(j) <= Y < YEDGES(j+1)
   ZEDGES(k) <= Z < ZEDGES(k+1)


Note: data outside the ranges of the EDGES vectors are excluded from the histogram, and not placed in the first or last bins.

An example:




MATLAB release MATLAB 7.3 (R2006b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
10 Jan 2011 Mathew

Mathew (view profile)

Hi, I've been unable to produce this error. I tried with 4 columns of 1,000,000 data points, with 20 edge points for each dimension.

Using too many edge points (histogram bins) will make the output array too big for matlab to handle.

In the linux program 'top', I saw the MATLAB process was using around 4% of the memory (system has 4GB). Maybe you could try the code below, and see if it works on yours.

>> x1=rand(1000000,1);
>> x2=rand(1000000,1);
>> x3=rand(1000000,1);
>> x4=rand(1000000,1);
>> e1=linspace(0,1,20);
>> e2=e1;e3=e1;e4=e1;
>> tic;n=histcnd(x1,x2,x3,x4,e1,e2,e3,e4);toc;

Elapsed time is 2.554106 seconds.

>> size(n)

ans =

20 20 20 20

Comment only
10 Jan 2011 Justin

Justin (view profile)


I'm trying to use your program but it gives me an error that says "out of memory". I've been feeding in 4 columns of 10000 data points into the program.


Comment only
17 Nov 2010 1.2

Added an example to the description.

18 Nov 2010 1.3

Added comments to explain the algorithm. Small optimization of code.

02 Dec 2010 1.5

Bug Fix: the behaviour is now consistent for data above and below ranges of the edges vectors.

Contact us