Be the first to rate this file! 7 Downloads (last 30 days) File Size: 2.85 KB File ID: #25914

Fast 2D histogram calculation

by Amanda

 

21 Nov 2009

Fast calculation of 2D histogram. Optionally displays surf plot of histogram.

| Watch this File

File Information
Description

Hist2D performs a fast calculation of 2D histograms. On a 2GHz processor, calculated and displayed a histogram of 1 million points in less than half a second.

HIST2D 2D histogram
 
  [H XBINS YBINS] = HIST2D(D, XN, YN, [XLO XHI], [YLO YHI])
  [H XBINS YBINS] = HIST2D(D, 'display' ...)
 
HIST2D calculates a 2-dimensional histogram and returns the histogram array and (optionally) the bins used to calculate the histogram.
 
Inputs:
      D: N x 2 real array containing N data points or N x 1 array of N complex values
      XN: number of bins in the x dimension (defaults to 20)
      YN: number of bins in the y dimension (defaults to 20)
      [XLO XHI]: range for the bins in the x dimension (defaults to the minimum and maximum of the data points)
      [YLO YHI]: range for the bins in the y dimension (defaults to the minimum and maximum of the data points)
      'display': displays the 2D histogram as a surf plot in the current axes
 
Outputs:
      H: 2D histogram array (rows represent X, columns represent Y)
      XBINS: the X bin edges (see below)
      YBINS: the Y bin edges (see below)
        
As with histc, h(i,j) is the number of data points (dx,dy) where x(i) <= dx < x(i+1) and y(j) <= dx < y(j+1). The last x bin counts values where dx exactly equals the last x bin value, and the last y bin counts values where dy exactly equals the last y bin value.
 
If D is a complex array, HIST2D splits the complex numbers into real (x) and imaginary (y) components.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
2D Histogram

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
23 Nov 2009 Bruno Luong

Speed is decent, but still cannot beat another more generic histogram submission:

>> tic; [Hout xbins ybins] = hist2d(x); toc
Elapsed time is 0.282145 seconds.

>> tic; [count xbins ybins] = histcn(x,xbins,ybins); toc
Elapsed time is 0.218104 seconds.

http://www.mathworks.com/matlabcentral/fileexchange/23897-n-dimensional-histogram

Let alone an even faster mex implementation
http://www.mathworks.com/matlabcentral/fileexchange/3957

So I would change the implicit speed claim in the title.

Bruno

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
2d Amanda 23 Nov 2009 09:53:05
histogram Amanda 23 Nov 2009 09:53:05
complex Amanda 23 Nov 2009 09:53:05

Contact us at files@mathworks.com