comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Finding Common Elements in Two Arrays

Finding Common Elements in Two Arrays
type: item
description: okay, this should better this time. Thanks to Dave Landers for his ideas. This program returns the indecies of where A match B (or the otherway around) Also, this is faster!nd now works with all types except structures (returns a message warning of wrong type if a structure is passed, and -2 value is returned!) -stephen Strebel --------------------------- cut here ------------------------------- ; ;+ ; NAME: ; where_array.pro ; ; PURPOSE: ; return the indecies of where vector B exists in vector A. ; Basicly a where(B eq A) where B and A are 1 dimensional arrays. ; ; ; CATEGORY: ; Array ; ; ; CALLING SEQUENCE: ; result = where_array(A,B) ; ; INPUTS: ; A vector the might contains elements of vector B ; B vector the we would like to know which of its ; elements exist in A ; ; OPTIONAL INPUTS: ; ; KEYWORD PARAMETERS: ; iA_in_B return instead the indecies of A that are in ; (exist) in B ; ; OUTPUTS: ; Index into B of elements found in vector A. If no ; matches are found -1 is returned. If the function is called ; with incorrect arguments, a warning is displayed, and -2 is ; returned (see side effects for more info) ; ; OPTIONAL OUTPUTS: ; ; COMMON BLOCKS: ; None ; ; SIDE EFFECTS: ; If the function is called incorrectly, a message is diplayed ; to the screen, and the !ERR_STRING is set to the warning ; message. No error code is set, because the program returns ; -2 already ; ; RESTRICTIONS: ; This should be used with only Vectors. Matricies other then ; vectors will result in -2 being returned. Also, A and B must ; be defined, and must not be strings! ; ; ; PROCEDURE: ; ; EXAMPLE: ; idl> A=[2,1,3,5,3,8,2,5] ; IDL> B=[3,4,2,8,7,8] ; IDL> result = where_array(a,b) ; IDL> print,result ; ; SEE ALSO: ; where ; ; MODIFICATION HISTORY: ; Written by: Dan Carr at RSI (command line version) 2/6/94 ; Stephen Strebel 3/6/94 ; made into a function, but really DAN did all ; the thinking on this one! ; Stephen Strebel 6/6/94 ; Changed method, because died with Strings (etc) ; Used ideas…
creator: stl
date: 1994-06-06T09:31:22-00:00