nanophd has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks,
I can't seem to find a way to determine the key of an array which is closest to a value. My data is essentially a bell shaped curve that I will eventually want to do some math on. I am trying to create a simple "full width at half max" type analysis. I am able to easily locate the maximum value and associated key in the hash, but what I am getting stuck on is how to determine the keys (one on each side of max) at which has a value closest to $hash{$max/2}.
My hash has the following values (sorted to make it easier to look at):
Step1: max value (302) has a key of "-2.4".-4 => 0 -3.9 => 0 -3.8 => 0 -3.7 => 1 -3.6 => 0 -3.5 => 1 -3.4 => 0 -3.3 => 0 -3.2 => 5 -3.1 => 19 -3 => 23 -2.9 => 50 -2.8 => 43 -2.7 => 28 -2.6 => 72 -2.5 => 165 -2.4 => 302 -2.3 => 168 -2.2 => 260 -2.1 => 151 -2 => 13 -1.9 => 1 -1.8 => 0 -1.7 => 0 -1.6 => 0 -1.5 => 0 -1.4 => 0 -1.3 => 0 -1.2 => 0 -1.1 => 0 -1 => 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding hash key related to closest value
by LanX (Saint) on Mar 12, 2014 at 16:48 UTC | |
|
Re: Finding hash key related to closest value
by hdb (Monsignor) on Mar 12, 2014 at 17:54 UTC | |
by nanophd (Novice) on Mar 12, 2014 at 18:02 UTC | |
|
Re: Finding hash key related to closest value
by tangent (Parson) on Mar 12, 2014 at 18:10 UTC | |
|
Re: Finding hash key related to closest value
by kcott (Archbishop) on Mar 13, 2014 at 05:41 UTC | |
|
Re: Finding hash key related to closest value
by Anonymous Monk on Mar 14, 2014 at 02:50 UTC |