LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I insert into an array only if the condition is true?

I am buiding an array made up of pairs of data from a file. I am going through line by line putting the values in an array and then taking the pairs of two indexes oring them and putting the number into another array. I do not know if there is more than one set on each line so I have to do a while loop to check.The problem is I have to get the indexes in pairs, so for example I take in the element from index 0 and 1 and or them index 2 and 3 and or them, I do not need the combination of 1 and 2 or 3 and 4 and etc. I am using the "Quotient & Remainder" to check if the index is even or odd, if it is even I take that element and the very next index's element, I or them and put them in another array, but if i
t is odd I do not want to put anything into the array. How can I go about doing that? Any help would be appreciated. I am using version 6.1 Thanks, Molly
0 Kudos
Message 1 of 5
(4,348 Views)
Put your build array inside the true case. In the false case, you wire the array from the shift register straight through without doing any modification. If you look at the shipping example called Separate Array Values, you should get a clue as to what I mean. If in either of the cases, you eliminate the build array, you will get only one array filled. Your conditions are a little more complex than the example but the concept is the same.
0 Kudos
Message 2 of 5
(4,348 Views)
Molly,

Rather than running while loop which only executes code every other time you could instead just do a little more math to get your index values. Just multiply the iterator (i) terminal by 2 for the first index and then add 1 to it for the second (you'd need to run the loop half as many times of course). This would be more efficient and easier to read in your code. One other tip is that when you are running a loop a specified number of times it's cleaner to use a for loop rather than a while loop.

Regards,
Ryan K.
NI
0 Kudos
Message 3 of 5
(4,348 Views)
Thank you for your help but, unfortunately this did not work for me I am not sure if it was because of the outer loop or what but, when the file is finally closed the array was not correct. Thanks though!! Molly
0 Kudos
Message 4 of 5
(4,348 Views)
Thank you so much, I can't believe I didn't think of that, it was that simple!! You should see how complicated I made it. Thank you so much, Molly
0 Kudos
Message 5 of 5
(4,348 Views)