Re: Select values from one array that match multiple values from an other array [message #82479 is a reply to message #82218] |
Thu, 13 December 2012 10:24  |
Sir Loin Steak
Messages: 42 Registered: January 2012
|
Member |
|
|
On Thursday, December 13, 2012 4:35:28 PM UTC, David Fanning wrote:
> David Fanning writes:
>
>
>
>> OK, I just added a POSITIONS keyword to SetIntersection
>
>> that will return the positions in vector A where the
>
>> values in vector B appear.
>
>>
>
>> A=[1,3,2,5,2,6,1,9]
>
>> B=[1,5]
>
>> C = SetIntersection(a, b, Positions=pos)
>
>> Print, pos
>
>> 0 6 3
>
>
>
> At Bob Stockwell's suggestion (and with his code!) I
>
> have added the keywords INDICES_A and INDICES_B
>
> to this program to allow you to return the matching
>
> indices in BOTH vectors. Note that this assumes the
>
> vectors A and B contain *unique* values. In other
>
> words, INDICES_A and POSITIONS are identical vectors
>
> IF vector A and B contain unique values. If they
>
> don't, then POSITIONS will contain ALL of the locations
>
> in vector A where the match occurs.
>
>
>
> You can find the updated program here:
>
>
>
> http://www.idlcoyote.com/programs/setintersection.pro
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
I was just about to post a question about this very topic - spooky! Would it also be possible to amend the SetDifference code so it also records positions, as I would like to know which elements of one array have no match in a different array.
Many thanks
|
|
|