comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Distance between two sets of datapoints
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Distance between two sets of datapoints [message #70254 is a reply to message #70240] Thu, 25 March 2010 07:55 Go to previous messageGo to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article
<4707b3ed-9e43-4863-977f-7fd091e62868@a4g2000prb.googlegroups.com>,
Maxwell Peck <maxjpeck@gmail.com> wrote:

> Hi All,
>
> I have two sets of data points, inputa and inputb, inputa has many
> more data points than the other. I need to find the distance between
> each point in inputa and all the points in inputb (hopefully without
> loops). At the moment I am using parts of distance_measure.pro to
> generate the full set of distances and subsetting indexes as required.
> The code follows. I can't see an easy way of generating the indexes
> though so that only the pairs i want are calculated (i.e. not
> calculating between inputb/inputb or inputa/inputa indexes).
>
> inputa and inputb can be very very large so I don't think i can use a
> matrix approach to do it vectorially and looping seems awfully slow.
>
> An alternative approach or other suggestions would be appreciated.
>
> Regards
>
> Max
>
>
> inputa = findgen(2,10)
> inputb = findgen(2,2)
>
> t = [[inputa],[inputb]]
> m=n_elements(t)/2
> n = m*(m-1)/2
>
> ii = 0L
> index0 = LINDGEN(m - 1) + 1 ; work array
> index1 = LONARR(n, /NOZERO)
> index2 = LONARR(n, /NOZERO)
>
> for i=0,m-2 do begin
> n1 = m - (i+1)
> index1[ii:ii+n1-1] = i
> index2[ii] = index0[0:n1-1] + i
> ii += n1
> endfor
>
> diff = abs(t[*,index1] - t[*,index2])
> res = sqrt(TOTAL(diff^2, 1))

If I understand you right, don't you want to do this?

na = 10
nb = 2
xa = FINDGEN(na)
ya = FINDGEN(na)
xb = FINDGEN(nb)
yb = FINDGEN(nb)

dist = FLTARR(na, nb)

FOR i = 0, nb-1 DO BEGIN
d = SQRT((xb[i] - xa)^2 + (yb[i] - ya)^2)
dist[0,i] = d
ENDFOR

I changed the notation to make the indexing simpler.

This computes the Cartesian distance between all pairs of
points in a and b.

You should loop over the smaller of na or nb.

Ken Bowman
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Highlight default button
Next Topic: IDL licensing

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:56:29 PDT 2025

Total time taken to generate the page: 0.00390 seconds