2D Histogram Matrix

version 1.0.0.0 (1.21 KB) by Kangwon Lee
Returns a matrix of number of points in each bins defined by two vectors.

13.1K Downloads

Updated 18 Jul 2006

No License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

function mHist = hist2d ([vY, vX], vYEdge, vXEdge)
2 Dimensional Histogram
Counts number of points in the bins defined by vYEdge, vXEdge.
size(vX) == size(vY) == [n,1]
size(mHist) == [length(vYEdge) -1, length(vXEdge) -1]

EXAMPLE

mYX = rand(100,2);
vXEdge = linspace(0,1,10);
vYEdge = linspace(0,1,20);
mHist2d = hist2d(mYX,vYEdge,vXEdge);

nXBins = length(vXEdge);
nYBins = length(vYEdge);
vXLabel = 0.5*(vXEdge(1:(nXBins-1))+vXEdge(2:nXBins));
vYLabel = 0.5*(vYEdge(1:(nYBins-1))+vYEdge(2:nYBins));
pcolor(vXLabel, vYLabel,mHist2d); colorbar

Cite As

Kangwon Lee (2022). 2D Histogram Matrix (https://www.mathworks.com/matlabcentral/fileexchange/1487-2d-histogram-matrix), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R11.1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: 2-Dimensional Histogram

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!