How to construct a weighed 2D histogram?
조회 수: 25 (최근 30일)
이전 댓글 표시
Hey,
I am finding it hard to construct a weighed 2D histogram.
Let us assume that we have two vectors, X and Y, of equal length N such that the entries in each of X and Y are not necessarily unique. Similarly, let's assume that W represents an array of N non-unique, non-integer values weighing each sample point [ X(i), Y(i) ].
To construct a standard 2D histogram, I am aware one can simply use
H = histogram2( X, Y )
to plot (along the z-axis) the sum/count of number of points per bin.
My question: how can I modify this to account for the weight of every sample point within a bin? That is, for the result to be the sum of the weights of all points within a bin.
(Note that this is not equivalent to merely weighing the count per bin by a constant value)
Thanks for any suggestions!
댓글 수: 0
답변 (2개)
John D'Errico
2019년 7월 12일
Just use accumarray to sum the weights in each bin.
댓글 수: 3
John D'Errico
2019년 7월 12일
Did you read the help for accumarray? Why not? Note that there are 8 examples of use of accumarray, here:
help accumarray
There will be more complete examples and explanations in
doc accumarray
READ THE HELP!
You will find that you first need to use discretize to bin each sample, so do that twice, once for each dimension. But again, you will find examples in the help. I cannot do better than to re-write the help, and how will that gain you or me?
help discretize
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!