Let's say I have two Tables A={1.0,2.3,1.5,3.0,1.1,}
, B={2,10,3,1,0}
and I'd like to plot a histogram in the following way:
- Divide the range of values of
A
intoN
bins of equal length(Max[A]-Min[A])/N
. - There will be some number of "points" (number of corresponding entries of
A
) in each bin. Count the number of points in each of the bins for which the corresponding entries ofB
lie between some valuesminB
andmaxB
. - Plot the resulting distribution of points in the bins.
Let's see how it works with the data given.
Max[A]=3.0
, Min[A]=1.0
, choose N = 2
(the choice is compeletly arbitrary). The width of the bin is 1. The first bin has three "points", because the values A[[1]]
, A[[3]]
and A[[5]]
lie between 1.0 and 2.0. The second bin has two "points", because the values A[[2]]
and A[[4]]
lie between 2.0 and 3.0.
Now, choose minB=1
, maxB=3
(again, arbitrarily). Then, out of three "points" in the first bin only i=1
and i=3
work, but not i=5
, because the corresponding value of B[[5]]
is outside of the closed interval $[minB,maxB]$. Out of two "points" in the second bin only i=4
works, but not i=2
, because the corresponding value of B[[2]]
is outside of the closed interval $[minB,maxB]$.
Thus the distribution is such that there are two points in the first bin and one point in the second bin.
How do I plot this histogram given A
and B
?
UPDATE: The problem arose while simulating the production of a neutrino beam. In the actual problem A
are energies of the neutrinos and B
are off-axis angles. I faked A
and B
to make it look simpler. This is the first time I'm using Mathematica in my research, so it takes hours to figure out things that other people can do in 2 minutes.
UPDATE2 Some possible data and corresponding outputs.
DATA: A={1,2,3,4,5}
, B={1,2,3,4,5}
, N=2
, minB=1
, maxB=3
, $bin1=[1,3)$, $bin2=[3,5]$ (note the open and closed intervals).
OUTPUT: bin1={2 points}
, bin2={1 point}
.
DATA: A={1,2,3,4,5}
, B={1,2,3,4,5}
, N=4
, minB=1
, maxB=3
, $bin1=[1,2)$, $bin2=[2,3)$, $bin3=[3,4)$, $bin4=[4,5]$ (note the open and closed intervals).
OUTPUT: bin1={1 points}
, bin2={1 point}
, bin3={1 point}
, bin4={0 points}
.
BinLists[A, (maxA - minA)/Length[A]]
is a possible starting point, then possibly followed by usage ofSelect
andPosition
in some way. $\endgroup$