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 #80671 is a reply to message #80658] Tue, 26 June 2012 18:35 Go to previous messageGo to previous message
Russell Ryan is currently offline  Russell Ryan
Messages: 122
Registered: May 2012
Senior Member
On Tuesday, June 26, 2012 5:28:56 PM UTC-4, Mats Löfdahl wrote:
> 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.)

So, that's going to work, but the distance you get "a" is probably not the minimum distance since you're working with angles. That said, you should look up the relevant equation for "great circle" distances to get the true minimum.
[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: Wed Oct 08 19:57:13 PDT 2025

Total time taken to generate the page: 0.00416 seconds