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

Home » Public Forums » archive » finding exclusive elements between two not-quite identical arrays
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: finding exclusive elements between two not-quite identical arrays [message #89741 is a reply to message #89740] Wed, 26 November 2014 03:05 Go to previous messageGo to previous message
Nikola is currently offline  Nikola
Messages: 53
Registered: November 2009
Member
If the arrays are small and there is no other restriction on using loops, you can do it like this:

a = [11, 19, 40]
b = [10, 20, 30, 40]
c = b
margin = 5
FOR i = 0, N_ELEMENTS(b)-1 do c[i] = TOTAL(ABS((b[i]-a)) LT margin) EQ 0
PRINT, WHERE(c NE 0)
2

a = [11, 23, 40]
b = [10, 20, 30, 40]
c = b
margin = 5
FOR i = 0, N_ELEMENTS(b)-1 do c[i] = TOTAL(ABS((b[i]-a)) LT margin) EQ 0
PRINT, WHERE(c NE 0)
2

a = [11, 23, 40]
b = [10, 20, 30, 40]
c = b
margin = 2
FOR i = 0, N_ELEMENTS(b)-1 do c[i] = TOTAL(ABS((b[i]-a)) LT margin) EQ 0
PRINT, WHERE(c NE 0)
1 2

Where margin obviously specify how close elements of A and B should be to consider them matching. I don't see a quick solution to do this with histograms especially if b does not have to be equispaced. The method above work well in that case as well:

a = [11, 35, 40]
b = [10, 17, 33, 40]
c = b
margin = 5
FOR i = 0, N_ELEMENTS(b)-1 do c[i] = TOTAL(ABS((b[i]-a)) LT margin) EQ 0
PRINT, WHERE(c NE 0)
1


On Wednesday, November 26, 2014 6:51:19 AM UTC, Brian Cherinka wrote:
> So I know how to find elements in one array that are not in a second, when both arrays have identical elements.
>
> A = [0,2,3,4]
> B = [0,1,2,3,4]
>
> print, where(histogram(A, omin=om) eq 0 and histogram(B,min=om) ne 0)+om
> 1
>
> Now I want to do the same thing, but with two arrays containing integers that aren't quite identical in each one. Some of the elements can be off by +- 1. So
>
> A = [11, 19, 40]
> B = [10, 20, 30, 40]
>
> Doing the above should return element index 2 (30) in B that is not in A, but I don't know how to do this. Any ideas?
>
> Thanks, Brian
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: get lat/lon from modis SIN grid
Next Topic: Giving Thanks

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

Current Time: Wed Oct 08 17:45:30 PDT 2025

Total time taken to generate the page: 0.00413 seconds