Home »
Public Forums »
archive »
Array matching?
Array matching? [message #50180] |
Thu, 14 September 2006 12:17 |
gknoke
Messages: 9 Registered: September 2006
|
Junior Member |
|
|
Hi, I'm trying to figure out a clever way to find all elements of two
vectors that are equal. I'm searching a 2d array for all instances in
which there is a large positive value above a certain threshold
immediately adjacent to a large negative value below the same
threshold. Currently my routine works like this:
diff = dat - shift(dat, [-1,0])
hi = where(diff gt threshold)
nhi = n_elements(hi)
for i=0,nhi-1 do begin
lo = diff[i-1]
if (lo lt -threshold) then dat[i] = (dat[i-1]+dat[i+1])/2.
endfor
This has a few checks to make sure the array indices aren't out of
bounds, but this gives you a flavor of what I'm trying to do. Ideally
I'd rather have something like this:
hi = where(diff gt threshold)
lo = where(diff lt -threshold)
lo = lo + 1
match = where(hi eq lo)
hits = hi[match]
dat[hits] = (dat[hits -1] + dat[hits+1])/2.
but I'm not sure how to compare two arrays in IDL to find the indices
where the values in one array match the values in another array without
using a for loop.
Any clever ideas how to do this would be appreciated.
--Greg
|
|
|
Current Time: Fri Oct 10 12:21:24 PDT 2025
Total time taken to generate the page: 0.56064 seconds