2D Histogram Calculation

버전 1.1.0.0 (1.75 KB) 작성자: Laszlo Balkay
Quick computation of two-dimensional histogram of bivariate data
다운로드 수: 10.5K
업데이트 날짜: 2011/10/5

라이선스 보기

function histmat = hist2(x, y, xedges, yedges)

Extract 2D histogram data containing the number of events of [x , y] pairs that fall in each bin of the grid defined by xedges and yedges. The edges are vectors with monotonically non-decreasing values.

The code is optimized no loop inside, it can be useful in the case of large dataset.

EXAMPLE

events = 1000000;
x1 = sqrt(0.05)*randn(events,1)-0.5; x2 = sqrt(0.05)*randn(events,1)+0.5;
y1 = sqrt(0.05)*randn(events,1)+0.5; y2 = sqrt(0.05)*randn(events,1)-0.5;
x= [x1;x2]; y = [y1;y2];

For linearly spaced edges:
xedges = linspace(-1,1,64); yedges = linspace(-1,1,64);
histmat = hist2(x, y, xedges, yedges);
figure; pcolor(xedges,yedges,histmat'); colorbar ; axis square tight;

For nonlinearly spaced edges:
xedges_ = logspace(0,log10(3),64)-2; yedges_ = linspace(-1,1,64);
histmat_ = hist2(x, y, xedges_, yedges_);
figure; pcolor(xedges_,yedges_,histmat_'); colorbar ; axis square tight;

인용 양식

Laszlo Balkay (2026). 2D Histogram Calculation (https://kr.mathworks.com/matlabcentral/fileexchange/9896-2d-histogram-calculation), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R13SP1
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Histograms에 대해 자세히 알아보기
버전 게시됨 릴리스 정보
1.1.0.0

I fixed the bugs reported previously.

1.0.0.0

The two tails of the distribution was mixed up. Thanks for Nicolas Loeff and Nedialko Krouchev revealing the error.