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

Home » Public Forums » archive » recursive routine
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
recursive routine [message #83828] Mon, 08 April 2013 02:21 Go to next message
Thibault Garel is currently offline  Thibault Garel
Messages: 55
Registered: October 2009
Member
Hi,
I am having a hard time to figure out how to write a recursive routine
for the case below.

I have 2 arrays of similar size that contain integers.

For the value 2 of A:
(a) I want to find the corresponding elements of B, B[i].
(b) Then, I search for the values of A that are equal to the B[i]
values found in step (a)
(c) repeat step (a) with new A values
and so on

Example:
A = [2, 7, 6, 2, 0]
B = [6, 3, 1, 4, 6]

(a) A[0] and A [3] have value 2 => the corresponding B elements are
B[0]=6 and B[3]=4
(b) the value 4 is not found in A
(b) the value 6 is found in A : A[2]=1
(c) value 1 does not exist in B

I could easily write the algorithm in this simple example (using the
where function), but cannot make it work with much larger arrays in
case of N "levels" , i.e. all the steps have to be repeated N times
because several elements match the condition at each step.

I guess that I should use a recursive routine... (?)

Any help much appreciated !
Thanks
Re: recursive routine [message #83876 is a reply to message #83828] Thu, 11 April 2013 06:22 Go to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
On Thursday, April 11, 2013 9:11:01 AM UTC-4, Matthew Argall wrote:
> I have a program called "ismember.pro" that does what you want for 1 iteration. You could put it in a loop...
>
>
>
> https://dl.dropboxusercontent.com/u/42944960/ismember.pro

Actually, I think this is exactly what you need and that you only need to call it once. I have been pretty lazy this morning and did not read your post carefully the first time.
Re: recursive routine [message #83877 is a reply to message #83828] Thu, 11 April 2013 06:11 Go to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
I have a program called "ismember.pro" that does what you want for 1 iteration. You could put it in a loop...

https://dl.dropboxusercontent.com/u/42944960/ismember.pro
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Grid help
Next Topic: object serialization in IDL?

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

Current Time: Wed Oct 08 17:01:20 PDT 2025

Total time taken to generate the page: 0.00397 seconds