Hi PERL-fans,
I have a problem with an array while coding a histogram:
The data is in an array
@data
I initialise my histogram array like:
@histo=();
Then, I loop over the datapoints and at each point compute in which bin that point would be:
for(my $i=0; $i<scalar(@data); $i++){
my $j=int(($data[$i]-$min)/$bin_width + 1);
$histo[$j]++;
}
The problem is, that there might be bins which are empty (if the histogram is not coarse). And the empty bins should be assigned to ZERO and not stay undef, as they are now.
I tried looping over the whole array histo after the procedure and checking each value if it was a number or not and set all non-numbers to zero, but this seems to be not really a nice and good solution... I also tried to initialise the histo array at the beginning (as i actually now how many bins i will have) with a for loop for 0..fullsize setting all the values to zero, however, i think there must be a better way of initialising an array properly.
many thanks for your advice!