If am doing histograms, I prefer to use arrays for binning. The general approach goes like this. First, in 1-d:
For example, if your $x_min == 100, and your $x_bin_width == 5, then for $x == 123.45 the line above would add one more count to $histo[4]. Note that there's an implicit int() around the contents of the []; the line above is equivalent to the slightly longer:$histo[ ( $x - $x_min )/$x_bin_width ]++;
Also note that when the point lands at a boundary between bins, this scheme assigns it to the bin on the right. E.g. using the same parameters as before if $x is exactly 125, the code above would add 1 to $histo[5], not to $histo[4].$histo[ int( ( $x - $x_min )/$x_bin_width ) ]++;
Now, for the 2-d case, it's basically the same idea:
$histo[ ( $x - $x_min )/$x_bin_width ][ ( $y - $y_min )/$y_bin_width ] +++;
the lowliest monk
In reply to Re: placing values into bins
by tlm
in thread placing values into bins
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |