On Mon, Sep 20, 2010 at 11:08 AM, Devon McCormick <[email protected]> wrote:
> scaleNums=: 3 : 0
>   0 1 scaleNums y
> :
>   'low hi'=. ((<./),>./)x
>   if. 0 *./ . = 11 o. ,y do.
>       nums=. y-<./,y
>       nums=. nums%>./,nums       NB. scale from 0 to 1
>   else.
>       nums=. y-<./10 o. ,y
>       nums=. nums%>./10 o. ,nums NB. scale from 0 to 1 for complex
>   end.
>   nums=. low+nums*hi-low
> )
>
> 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
)

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

Reply via email to