Counts in each bin for 2d histogram ?

I have two vectors X and Y. To construct a 2D histogram, I have to create a grid on scatter plot of X,Y. And count number of data points in each small square of the grid that will be my frequency. Can someone help me how to decide number of bins and any matlab function to count the frequency in each small square ?

답변 (1개)

Stephen23
Stephen23 2016년 2월 4일

0 개 추천

Have a look at these functions:
histcounts2 Introduced in 2015b
histcn on FEX

댓글 수: 5

dipak sanap
dipak sanap 2016년 2월 4일
Thanks for reply but my matlab version dose not have these fucntion. I have only, histc. Do you have any idea how to use this to construct 2D histogram ?
Stephen23
Stephen23 2016년 2월 4일
편집: Stephen23 2016년 2월 4일
That is exactly why I gave you the link to histcn on FEX. It creates a 2D histogram with the outputs you want. That is why I gave you a link to it. Note that it is a third-party function, so you will need to download it and put in on your MATLAB path or in the current directory. The download button is in the top right corner, labelled "Download Zip".
Brando Miranda
Brando Miranda 2017년 12월 14일
do you know how to plot things with histcounts2?
Steven Lord
Steven Lord 2017년 12월 14일
If you want to see a 2-dimensional histogram plot, use histogram2 instead of histcounts2. The interfaces of those two functions are very similar, but the intent of the histcounts2 function is to let you bin the data without plotting anything. In histogram2, the ouput is the graphics object.
histogram2() gives an object with lots of info, if you choose to accept it:
x = randn(1000,1);
y = randn(1000,1);
h = histogram2(x,y)
h =
Histogram2 with properties:
Data: [1000×2 double]
Values: [13×13 double]
NumBins: [13 13]
XBinEdges: [-3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3]
YBinEdges: [-3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3]
BinWidth: [0.5 0.5]
Normalization: 'count'
FaceColor: 'auto'
EdgeColor: [0.15 0.15 0.15]
plus more...

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2016년 2월 4일

댓글:

2017년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by