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

Home » Public Forums » archive » Re: locating the closest values?
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: locating the closest values? [message #80680 is a reply to message #80678] Tue, 26 June 2012 14:28 Go to previous message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den tisdagen den 26:e juni 2012 kl. 22:55:34 UTC+2 skrev anil:
> Hi,
> I have two datasets/files. 1st one contains the values i want to find
> (latitudes and longitudes) and the second file contains 3 columns as
> longitude latitude and depth.
> What i want to do is to read my desired values from file 1 and find
> the closest values in file 2 and the corresponding 3rd column(depth)
> from file 2. here is what i did:
> 1st file:
> 42.25 30.57
> 41.17 32.58
> ......
> 2nd file
> 42.55 34.42 1000
> 41.54 33.21 1500
> .......
> what i did is :
>
> difference1=abs(lon-desiredlon)
> a1=min(difference1,index1)
>
> difference2=abs(lat-desiredlat)
> a2=min(difference2,index2)
>
> in this case, lon(index1) and lat(index2) become my desired values. no
> problem with that. but how do i get the 3rd column. i could not match
> index1 and index2 with where function.
> what am i missing here?

Index1 and index2 are different because being close in one of lat and lon is not the same as being closest in both. I suspect what you want is something like a=min(sqrt(difference1^2+difference2^2),index), which should give you the index to the point with the shortest distance from the desired point. (You may want to scale the differences to length units first.)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Problem with Parinfo on Craig B. Markwardt's MPFITPEAK
Next Topic: Marshall Perrin's library subreg.pro question

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

Current Time: Fri Oct 17 21:30:55 PDT 2025

Total time taken to generate the page: 0.40190 seconds