I've got a routine that computes the mean and standard deviations from an array ($closeData). However, I'd like the routine to skip the the first 97 records. Here is my code that can process the entire array:
I'm guessing I need adjust in both the function for standard_deviation adn the for... loop. I've tried manipulating count($std) in the function and $i in the for loop, but nothing as worked so far. Thanks for any help.
Chandler
I ran over my dogma with karma!
Code:
#Function for calculating Standard Deviation
function standard_deviation($std)
{
$total;
while(list($key,$val) = each($std))
{
$total += $val;
}
reset($std);
$mean = $total/count($std);
while(list($key,$val) = each($std))
{
$sum += pow(($val-$mean),2);
}
$var = sqrt($sum/(count($std)-1));
return $var;
}
$stdev = standard_deviation($closeData);
#Loop through array
for ($i = 0; $i < count($closeData); ++$i)
{
$mean_Data[$i]=$closeData[$i];
$up1_Data[$i] = $closeData[$i] + $stdev;
$dn1_Data[$i] = $closeData[$i] - $stdev;
$up2_Data[$i] = $closeData[$i] + $stdev * 2;
$dn2_Data[$i] = $closeData[$i] - $stdev * 2;
}
I'm guessing I need adjust in both the function for standard_deviation adn the for... loop. I've tried manipulating count($std) in the function and $i in the for loop, but nothing as worked so far. Thanks for any help.
Chandler
I ran over my dogma with karma!