Page 1 of 1

variable assignment problem?

Posted: Fri Mar 17, 2006 9:12 am
by captainpete
I'm using a PEAR extension to create wind distribution histograms and I'm having some trouble assigning a variable's value to another variable and passing it into the method: setBinOptions (links to class document).
Here's the code I'm using, and the explaination is below:

Code: Select all

# Read in the data set
$handle = fopen("wind3.csv", "r");
while (($data = fgetcsv($handle, 100, ",")) !== FALSE) {
	$wind_speed[] = $data[0];
	$wind_direction[] = $data[1];
}
fclose($handle);

# Get max windspeed for the histogram calculation
$max_wind_int = ceil(max($wind_speed));

# Create an instance of the histogram (calculation part)
$h = new Math_Histogram();

# Determine the number of bins based on the max wind speed
$default_bins = 20;
if($max_wind_int > $default_bins){
	$max_bin = $max_wind_int;
}else{
	$max_bin = $default_bins;
}
$num_bins = $max_bin;

$h->setBinOptions($num_bins,0,$max_bin);

# THERES MORE AFTER THIS THAT CREATES THE PLOT, BUT ISN'T IMPORTANT...
For the data I'm using, $max_wind_int turns out to be 23. I want the number of bins to be equal to the maximum wind value so that each bin has a range of 1 mph. The above code does not appear to be passing $num_bins into setBinOptions correctly though. It is creating a histogram with a completely different value than what should be stored in $num_bins (23). When I echo $num_bins, it's returning the value 23, but the histogram only has 10 bins. Knowing that $num_bins should be 23, I directly assigned it with this value and it returns a histogram with 23 bins. I'm lost as to what may be going on here. I'm using PHP v 4.4.1