LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

recursion in labview

Hi all

I was wondering if anyone has every wanted to be able to use recursion
in Labview and if so, how did they solve it?

My problem is that I would like to use labview to present visual
stimuli to subjects participating in an experiment investigating the
human visual system. There are 10 stimuli, each of which I would like
to present 5 times but in random order.

previously I have in C used a ran() to select a stimulus, check
whether the stimulus has been presented more than 5 times and if so
use ran() again to choose another stimulus.

Have tried to do the same thing in labview but with no success, it
doesn't seem to like recursion.

Any suggestions?

A very new labview programmer
0 Kudos
Message 1 of 6
(3,391 Views)
Stuart Smith wrote:

> Hi all
>
> I was wondering if anyone has every wanted to be able to use recursion
> in Labview and if so, how did they solve it?
>
> My problem is that I would like to use labview to present visual
> stimuli to subjects participating in an experiment investigating the
> human visual system. There are 10 stimuli, each of which I would like
> to present 5 times but in random order.
>
> previously I have in C used a ran() to select a stimulus, check
> whether the stimulus has been presented more than 5 times and if so
> use ran() again to choose another stimulus.
>
> Have tried to do the same thing in labview but with no success, it
> doesn't seem to like recursion.
>
> Any suggestions?
>
> A very new labview programmer

I have always been con
fused about recursion, that is where a function calls
itself right ??
I think in order to make this work you would have to make the VI re-entrant
(under VI setup->Execution Options select Reentrant Execution).
This could be accomplished I believe without doing this , by simply keeping
a count of each of the stimuli, external to the function.

Let me know maybe I can whip someting up.
Kevin Kent
0 Kudos
Message 2 of 6
(3,391 Views)
"Kevin B. Kent" wrote:

> Stuart Smith wrote:
>
> > Hi all
> >
> > I was wondering if anyone has every wanted to be able to use recursion
> > in Labview and if so, how did they solve it?



>
> I have always been confused about recursion, that is where a function calls
> itself right ??
> I think in order to make this work you would have to make the VI re-entrant
> (under VI setup->Execution Options select Reentrant Execution).
> This could be accomplished I believe without doing this , by simply keeping
> a count of each of the stimuli, external to the function.

It never hurts to check out the NI Web site: a search for "recursive" turned up
a nice factorial example that uses VI Server and a Call by Reference node to do
the job. Here's the URL:

http://d
igital.ni.com/explprog.nsf/websearch/dcce30e278e2cbb88625674b007d45b6

Reentrancy is indeed used. LabVIEW isn't LISP, though, and recursion is pretty
difficult to achieve as of LabVIEW 5.1. Most (almost all?) LabVIEW tasks are
probably better done using iterative methods, both in terms of programming
simplicity and performance.

Regards,
John Lum
National Instruments
0 Kudos
Message 3 of 6
(3,391 Views)
Recursion can also in some cases be achieved by the use of shift registers.
I had an example doing a recursive listing of a directory, with 2 shift
registers. If I find it, I'll try to post it.

-Michel Farhi
0 Kudos
Message 4 of 6
(3,391 Views)
Can the attachment be a solution? 🙂
( in fact, non-recursive execution, but it works well)

i will be happy if you send real recursive VI examples to me.
ozan...

Mike wrote in message
news:8i4cdd$med$1@news.smartworld.net...
> Recursion can also in some cases be achieved by the use of shift
registers.
> I had an example doing a recursive listing of a directory, with 2 shift
> registers. If I find it, I'll try to post it.
>
> -Michel Farhi
>
>
>
>



[Attachment recursive dir.vi, see below]
0 Kudos
Message 5 of 6
(3,391 Views)
I wrote the attached recursive VIs some time ago, just to see how that could be
implemented. The VIs don't use reentrency or Call by reference or anything (as far
as I remember they were done in LV 2.52 or so). They use shift registers and, most
important, a VI that implements a FIFO stack. Admittedly, the VIs are quite
cryptic, but they work and demonstrate the principle.


Regards

Franz Ahlers

(P.S.: the VIs calculate N! and f(N)=N*f(N-1)*f(N-2). The second function was made
up by me to demonstrate a little bit more complicated case than just N!)

John Lum schrieb:

> "Kevin B. Kent" wrote:
>
> > Stuart Smith wrote:
> >
> > > Hi all
> > >
> > > I was wondering if anyone has every wanted to be able to use recursion
> > > in Labview and
if so, how did they solve it?
>
>
>
> >
> > I have always been confused about recursion, that is where a function calls
> > itself right ??
> > I think in order to make this work you would have to make the VI re-entrant
> > (under VI setup->Execution Options select Reentrant Execution).
> > This could be accomplished I believe without doing this , by simply keeping
> > a count of each of the stimuli, external to the function.
>
> It never hurts to check out the NI Web site: a search for "recursive" turned up
> a nice factorial example that uses VI Server and a Call by Reference node to do
> the job. Here's the URL:
>
> http://digital.ni.com/explprog.nsf/websearch/dcce30e278e2cbb88625674b007d45b6
>
> Reentrancy is indeed used. LabVIEW isn't LISP, though, and recursion is pretty
> difficult to achieve as of LabVIEW 5.1. Most (almost all?) LabVIEW tasks are
> probably better done using iterative methods, both in terms of programming
> simplicity and performance.
>
> Regards,
>
John Lum
> National Instruments
0 Kudos
Message 6 of 6
(3,391 Views)