Showing results for 
Search instead for 
Did you mean: 

Implementing SubVI with feedback node in a For Loop

Good day programmers,

I have a discrete subVI that I would like to implement in a For Loop. The SubVI depends on values from previous loop iteration (While loop iteration), i.e. there is feedback node/shift register inside so if you just implement subVI in the For Loop as is, the previous value in the SubVI is going to contain value from the previous For Loop iteration value not the actual value from the previous While Loop operation. How do we go around this?

As a simple example, let me use the discrete pt-by-pt moving average VI.  I have attached a For Loop in which I have an array of 4 values that are offset with random values on top of for noise injection. Then I have independent 4 pt-by-pt moving average block running in parallel and one pt-by-pt moving average block in the For Loop. You can see that each For Loop iteration value affects the previous value in the moving average block.


  1. Can you delay the iteration inside of the SubVI by the number of elements in the input array (i.e. array size)? Will this work? But there is no such thing as dynamic feedback node with a variable delay like the FPGA Discrete Delay block.
  2. Alternatively we can force feed the current value and previous value to the SubVI inside the For loop. This sounds messy.


It would be really nice to be able to implement such SubVI as the ptbypt moving average for a variable size array. That way you don’t have to index the array and do it individually element by element. Seem like it should be simple but I can’t figure it out.


I hope my explanation of the problem is clear enough. I appreciate any advice.



0 Kudos
Message 1 of 6

I'm not on a LV machine to look at your code, but it sounds like this *might* be a case where the subvi should be reentrant (with pre-allocated clones).   Then each instance of the subvi that you drop on the diagram has its own distinct feedback node.  The one you place in While Loop "A" is completely distinct from the one you place in For Loop "B".



-Kevin P

0 Kudos
Message 2 of 6

I'm not sure I understand your question, are you wanting to use Mean Pt by Pt on several different pieces of data, which you don't know the number of until later?


I do not know a way to do this, but I have put Mean Pt by Pt in a case structure (one instance in each case) which is just selected by the iteration terminal of the loop. This makes it a little more compact on your diagram.

CLA // LabVIEW 2016 // BALUG // Unofficial Forum Rules and Guidelines
0 Kudos
Message 3 of 6

Hi Kevin, 


The ptbypt Mean is re-entrant by default.

0 Kudos
Message 4 of 6

Hi gregoryj,


Thank you for your reply.


Yes I would like to use the Mean ptbypt on several pieces of data. We know the number of data for a given application but it may be different for a other application.


I am not sure I follow your suggested implementation.



0 Kudos
Message 5 of 6

Like this:



CLA // LabVIEW 2016 // BALUG // Unofficial Forum Rules and Guidelines
0 Kudos
Message 6 of 6