> From: Raul Miller
> Sent: Tuesday, 21 September 2010 03:43
> On Mon, Sep 20, 2010 at 11:08 AM, Devon McCormick wrote:
> > scaleNums=: 3 : 0
> >   0 1 scaleNums y
> > :
> >   'low hi'=. ((<./),>./)x
...
> >
> > It could be terser but I wrote it quite a while ago.
> 
> If you want terser, I would be tempted to do something like this:
> 
> scaleNums=:3 :0
>   0 1 scaleNums y
> :
>   'lowX magX lowY magY'=.x ,&(-~/\@(<./,>./)),10 o.y
>   lowX+magX*(y-lowY)%magY
> )

Thanks guys,
The following combines the functionality/brevity of versions to date:

rescale=:3 :0
  1 rescale y
:
  'data xtrm'=. 2{.boxopen y
  'lowX magX lowY magY'=. (2{.x) ,&(-~/\@(<./,>./)) 10 o. xtrm,,data
  lowX+magX*(data-lowY)%magY
)

   rescale 4 1 9 5 3.5 7             NB. obtains min & max from data
0.375 0 1 0.5 0.3125 0.75
   rescale 4 1 9 5 3.5 7;0 10        NB. give min & max possible vals if not in 
data
0.4 0.1 0.9 0.5 0.35 0.7
   15 rescale 4 1 9 5 3.5 7;0 10     NB. "out-of-10" to "out-of-15"
6 1.5 13.5 7.5 5.25 10.5
   _5 10 rescale 4 1 9 5 3.5 7;0 10  NB. "out-of-10" to "from _5 to 10"
1 _3.5 8.5 2.5 0.25 5.5

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to