LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Build Array Question

Hi,
 
I am wondering how to build a selective array from a continually changing stream of data. For example in the attached picture, I wish to append to the array only even numbers. So the resulting array should be [2 4 6...]. However, I am aware that for a case structure, an output terminal is required, so instead my output reads [0 2 0 4 0 6...], since the default value in the false case is zero. Is there a way to build an array that will only append new elements when certain conditions are met? (in this case, the condition being if the number is even).
 
I am aware that you can use a sort array function block, then remove the zeros. Is there a better way to perform this task that I need? In my actual program, I need to record the value of the time at a couple values at the turn of the hour when certain conditions are met, then feed the new array to a graph. Thanks,
 
Adam
0 Kudos
Message 1 of 4
(3,548 Views)
You can just put the build array part into the case statement.



You can also switch the build array to concatenate inputs mode (right click on it), and use arrays to output from your case statement (using empty arrays when you don't want to add anything)



Ideally you avoid puting build array into a loop, since reallocating large arrays can really slow down a program (shouldn't be a problem for small arrays).

Message Edited by Matt W on 11-21-2006 08:27 PM

Message Edited by Matt W on 11-21-2006 08:28 PM

Download All
0 Kudos
Message 2 of 4
(3,537 Views)

Matt,

I think I can follow the VI where the build array node (which appends elements to and increments the elements of the array) is placed within the case structure: when the element is indeed even, the true case appends it to the array, where as in the false case, the index (#x) remains constant (because the build array node is not present in the false case).

However I am a little confused on the mechanism of the VI where the main build array node is located outside of the case structure and the smaller build array node is located in the true case of the case structure. From what I can infer from the highlight execution tool in LabVIEW, the value of the index of the smaller build array node is #1 and that of the empty array output from the false case is #0, and this index is added to the index of the build array node located outside of the case structure, which adds the index of the smaller build array node to determine the placement of the element in the final array. Is this correct? Thanks!

 

Adam   

0 Kudos
Message 3 of 4
(3,497 Views)
For arrays highlight execution displays the length of the array so #1 means an array of length 1, and #0 an array of length of 0. So I'm either adding 1 or 0 elements to the end of the array I'm building (and adding zero elements doesn't change the array).
0 Kudos
Message 4 of 4
(3,476 Views)