10-18-2007 07:44 PM
10-18-2007 08:04 PM
10-18-2007 08:22 PM
10-18-2007 08:32 PM
10-18-2007 11:04 PM - edited 10-18-2007 11:04 PM
@Qurple wrote:
That doesn't work because the input to the case structure is an array and the output is an element of the array so they cannot be wired together.
Hi Qurple,
If your loop needs to output an array, then that's the kind of data you'll need to keep track of in your loop. The best way to do this in LabVIEW is with a shift register. It's not as simple as allowing an "if" statement, since with a dataflow language like LabVIEW, you must define a value to "flow" through the wires and tunnels for every possible case of code execution. So in your situation, the easiest way to do this is to have a shift register that keeps track of the array subset you want to output, and you can add/remove items to this array, or leave it alone. Here is a screenshot showing two approaches:
Note that there aren't actually two separate case structures in the loops, I'm just showing you the contents of both cases to help in your understanding. In approach #1, we start with an empty array, and add new elements to it (with the Build Array function) whenever a condition is met (in my case, I'm simply adding all elements greater than 2). In approach #2, we actually start with the entire array, and remove elements from it (with the Delete from Array function). Note that approach #2 is a bit more tricky, since we must keep track of the index into the array where we are when we're looking at a value to see if it needs to be deleted. Approach #1 is by far the most common approach to this problem, although Approach #2 would be more efficient if your output array is going to contain most of the elements from your input array.
I hope this helps you understand the issue a little more clearly. I remember when I first learned LabVIEW, shift registers were one of the more difficult concepts for me to grasp. But they are truly essential for just about any conditional coding you find yourself doing.
Good luck,
-D
Message Edited by Darren on 10-18-2007 11:04 PM