comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: HELP: Finding Array Element Positions

Re: HELP: Finding Array Element Positions
type: item
description: In article <772920404snz@babbage.demon.co.uk> Richard@babbage.demon.co.uk writes: > A PV-WAVE (version 4.20 on Solaris 2.3) Array Question: > > I have two string arrays, e.g. > > STRARR (5) = ['a','b','c','d','e'] > STRARR (2) = ['b','e'] > > I wish to find the elements which are common, i.e the result would be > > INTARR (2) = [1,4] > > I am currently performing this in a FOR loop (sacrilege!). With WAVE's > array manipulation I would expect there to be a more elegant solution. Hi, well, about a month ago a posted this exact program to the net, and there was lots of other discussion about this problem. Here is the best solution (from misc net discussion that I converted into a program) -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,…
creator: stl
date: 1994-06-30T06:11:43-00:00