LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop with case structure not executed inside while loop with condition from the first loop result

Solved!
Go to solution

Hi,

 

I am trying to process some arrays through case structure then use the result to do integration then use the integration result to compare and loop back to select the cases. I have the feedback node in there with initializer so the case can be selected in the first loop. However, the for loop with case structure doesn't seem executed and I couldn't figure out why it doesn't work. My code is attached. Any help or suggestion are appreciated. Thanks.

0 Kudos
Message 1 of 7
(2,762 Views)

A FOR loop executes as many times as the shortest autoidenxing input array. On your first iteration of the while loop, the blue array is empty and the FOR loop is skipped, outputting an empty orange array. From then one, that orange array will be empty forever because it forces zero iterations on the second FOR loop, no matter how big the other arrays are.

 

Can you explain in simple words what you are trying to do? This is definitely not the solution..

Message 2 of 7
(2,724 Views)
Solution
Accepted by topic author ArthurCHS

Run with highlight execution turned on, even run it one step at a time.

 

On your first while loop iteration, you have initialized two feedback nodes with arrays of 10 elements.  But the 3rd array you are auto-indexing on comes from your For Loop that is essentially a Ramp function from 0 to your iteration value of your outer while loop.

 

So on your 0th iteration, you send two 10 element arrays and one 0 element array to the bigger For Loop.  It will run 0 times and thus output a 0 element array (orange wire).  From then on, all future iterations will be getting a 0 element array from the feedback nodes and thus your inner loop will never run.

 

Try putting an increment function between the while loops i node and the N node of the small For Loop.  That way you'll start off with a 1 element For Loop.  You'll see it behave differently.

 

But I don't understand what you are really trying to do here.  Rethink your logic and try again.

Message 3 of 7
(2,720 Views)

Thanks for the suggestions! Sorry if seems confusing. I use random values and logic in the case structure and in the while loop because that shouldn't make differences. To explain what I am trying to do more, I am getting force data from a sensor in the formation just like the smaller for loop, it comes in as a keep-growing array. I need to process the data under 2 different scenarios then do integration of the processed force data with some simple math to give me the result(speed). Different results(speed) then decide which case the force go to next.

With your suggestions, it clear my head and my question more. I guess the question becomes how to make that for loop run with the feedback condition as many times as the size of the smaller for loop as the input array keep growing bigger and bigger. In other words, when the smaller for loop send an array of 10 elements, run for loop 10 times. When the smaller for loop send an array of 100 elements, run the for loop 100 times. Thanks!   

0 Kudos
Message 4 of 7
(2,691 Views)

@ArthurCHS wrote:

Thanks for the suggestions! Sorry if seems confusing. I use random values and logic in the case structure and in the while loop because that shouldn't make differences. To explain what I am trying to do more, I am getting force data from a sensor in the formation just like the smaller for loop, it comes in as a keep-growing array. I need to process the data under 2 different scenarios then do integration of the processed force data with some simple math to give me the result(speed). Different results(speed) then decide which case the force go to next.

With your suggestions, it clear my head and my question more. I guess the question becomes how to make that for loop run with the feedback condition as many times as the size of the smaller for loop as the input array keep growing bigger and bigger. In other words, when the smaller for loop send an array of 10 elements, run for loop 10 times. When the smaller for loop send an array of 100 elements, run the for loop 100 times. Thanks!   


You really need to re-think form scratch, or explain it better. An array cannot grow forever, or you'll run out of memory eventually.

Maybe if I understand your problem (among all the noise of confusing statements), you just have a FOR loop that processes all elements of a 1D array, one element per iteration until it runs out of elements. This can be easily done as long as that array is the only autoindexing input. If you are autoindexing on several arrays, the shortest wins when the number of iterations is determined. You can program around that, but you still need to think hard what should happen in iterations where one array runs out of elements early.

 

Can you take a step back and explain exactly what your program should do. Many times, you don't even need a FOR loop and can operate on arrays directly.

 

Why is the array growing? Do you get a fixed number of elements from the device and are growing the array locally? Does the device resend earlier duplicate data with each transmission? What exactly are you "integrating" and how?

0 Kudos
Message 5 of 7
(2,682 Views)

Are you sure you even need feedback nodes going to your inner For Loop?

 

One annoying "feature" that is turned on by default in LabVIEW is to auto-insert feedback nodes if you wire something that causes circular data dependencies.  I have never wanted to insert a feedback node that I didn't intentionally put it.  But there are plenty of times where I accidentally connected to the wrong node and created a circular dependency.  I want my wire to broken rather than auto-insert a feedback node.

 

The reason I bring that up is I don't see the purpose of your feedback nodes.  If you are forever growing data in an array like you just said, and continually doing calculations on that ever growing array, I don't see why you need to remember what happened in the previous loop iteration.  Your old data would still exist in the original growing array.  So I think you might only need one feedback node for the storing the incoming data, not others acting on calculation results.

 

As Altenbach said, take several steps back and truly think about what you are trying to do.  Write it down on paper as pseudocode or a flowchart to get your thoughts in order before you start laying down wires on a block diagram.

 

0 Kudos
Message 6 of 7
(2,661 Views)

Thanks for the suggestions. I was able to reshape the structure, remove one of the feedback node(the one for back calculating). and adjust the arrays properly to the same size then auto-indexing them to a for loop. I am still working on a few changes to make the program work properly but I got your ideas and that should be good.

Message 7 of 7
(2,631 Views)