From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Recursion

Hello all,

 

I have some questions regarding recursion in LabVIEW.

 

Currently I'm working on a nice application for analyzing experimental data.

1st step:  Raw experiment data is saved (as a row in a DB table).

2nd step: Data is manipulated.

3rd step:  The manipulation result is analyzed.

 

The recursion takes place in the data 2nd step - manipulation. This will happen for manipulation of manipulation.

 

Simple example:

Lets say A, B and C are raw data.

The manipulations will be defined as:

M1=A+B

M2=M1+C

 

I called the raw data (A,B,C) "primitives".

Lets call the recursive VI "Calc".

 

Calculating M2 will look like this:

Calc(M2)=Calc(M1)+Calc(C)=Calc(A)+Calc(B)+Calc(C)=A+B+C

 

The recursion "stopping condition" is operating it on a primitive. In this case, it will return its value.

 

So far so good for theory, but it is the first time I'm writing recursion in LabVIEW and not sure what is the best way to do it. My worry is mainly of memory usage, since I know recursion is a huge memory consumer. I'm not sure how LabVIEW will handle many levels of recursion (lets say ~20). The manipulation will be more complex than "+".

 

My questions are:

1. What is the best way to write a recursive VI?

2. How efficient LabVIEW is with a recursive VIs? Will it handle ~20 levels?

 

I'm using LabVIEW 2010, Windows XP, standard PC.

 

Thank you,

 

Amir.

 

0 Kudos
Message 1 of 6
(2,639 Views)

Hi Amir,

 

why do you need recursion here?

When "Calc(x)" is always the same operation you can apply Calc() on all of your data. Then you simply have to code the different M(x)-steps on your data - even 20 of them shouldn't need recursion. And don't forget: LabVIEW knows how to handle calculations on arrays...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(2,633 Views)

@Amir_Y wrote:

My questions are:

1. What is the best way to write a recursive VI?

2. How efficient LabVIEW is with a recursive VIs? Will it handle ~20 levels?

 


1. Just pull down the VI icon to the active VI and you have a recursive function. Dont forget a stop condition! 🙂

2. Rather efficient, if it can be done in C# it should work in LV. 20 levels shouldn't be a problem unless each level creates massive data amounts and spawn lots of kids.

 

Generally though, LV is more efficient on arrays. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 6
(2,626 Views)

I forgot to mention that the manipulations are dynamic.

The user can define the manipulation, and, of course, manipulation on manipulation.

This is why I cannot hard code the manipulations.

 

I hope this explians better,

 

Amir.

 

0 Kudos
Message 4 of 6
(2,618 Views)

Hi Amir,

 

maybe you could use a state machine to do steps of calculation instead of recursion (which will be one fixed type of manipulation done multiple times). That way your user can use a "batch script" to control the states...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 6
(2,611 Views)

Then i'd make a Enum of manipulations as in parameter to the VI and have a Case for each manipulation type, it doesn't make much difference from a structural standpoint.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 6
(2,606 Views)