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

Home » Public Forums » archive » Locating desired values in an array.
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 desired values in an array. [message #89098 is a reply to message #89093] Thu, 24 July 2014 05:13 Go to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
Here is a solution using Histogram and reverse indices.

;Create data
tn = [replicate(3, 5), replicate(2, 3), replicate(9, 8)]
lat = 42 + randomu(5, n_elements(tn))

;Histogram to find repeated track numbers
hist = histogram(tn, MIN=0, REVERSE_INDICES=ri)

;Allocate memory to result.
nHist = n_elements(hist)
theNumber = fltarr(nHist)
theIndex = intarr(nHist) - 1

;Loop through each bin
for i = 0, nHist-1 do begin
;Only analyze bins with something in them
if ri[i+1] gt ri[i] then begin
;Find the closest number and its index
theNumber[i] = min( abs( 42 - abs(lat[ri[ri[i]:ri[i+1]-1]]) ), iMax )
theIndex[i] = ri[i] + iMax
endif
endfor

;Weed out empty histogram bins
iKeep = where(theIndex ne -1)
theNumber = theNumber[iKeep]
theIndex = theIndex[iKeep]
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL and C inter-language communication / call_external()
Next Topic: how can you convert CMIP5 model output time ?

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

Current Time: Fri Nov 28 12:25:42 PST 2025

Total time taken to generate the page: 0.88108 seconds