08-26-2010 11:19 AM
Hi,
I am kind of rusty, I want to build array in the diagram below.
Note: I know I can use simpler method to achieve this goal, but the specific example is important to my larger scope
I expect the results:
0
1
2
4
5
10
hence I do not want the zeros to appear.
08-26-2010 11:27 AM - edited 08-26-2010 11:28 AM
Build Array.vi will work. Use a shift register initialized with a zero at index 1, and put the Build Array.vi in your False case.
EDIT: BTW, I don't know what your "larger scope" is but using build array in a loop with large arrays is inefficient.
08-26-2010 11:28 AM - edited 08-26-2010 11:29 AM
The easiest way is to use a shift register with an empty array as the initializer. In the true case, use Build Array, and in the false case wire the array through.
What's happening here, is in your false case you are adding a default value (0) to the array, rather than no value, which is what you are assuming happens. (You can tell by the little white box in the tunnel on the case structure).
08-26-2010 11:38 AM
Maybe this ?
08-26-2010 12:00 PM - edited 08-26-2010 12:01 PM
Does the arrayALWAYS contain (or start with)
0
1
2
4
5
10
???
If so, then you could simply initialize the array by having an array constant with those elements pre-entered.
08-26-2010 12:09 PM
08-26-2010 12:13 PM
@jcarmody wrote:
Just curious, but is this better, worse or same as using a case structure. My inclination is it would be better to not build an array every iteration, so the case structure would be a better solution. Thoughts?
08-26-2010 12:13 PM - edited 08-26-2010 12:14 PM
@jcarmody wrote:
I am in the habit of using a Case structure here. Using the Select primitive means that the Build Array will operate in every cycle and the wire branching has the potential to mess with inplaceness.
Edit: (Great?) minds think alike.
08-26-2010 12:17 PM - edited 08-26-2010 12:22 PM
I understand, but my solution covers LESS AREA on the Block Diagram and that's the most important thing :O.
<edit - added new snippet>
I'd have done it differently if this was meant to handle large amounts of data.
08-26-2010 12:39 PM
@jcarmody wrote:
I understand, but my solution covers LESS AREA on the Block Diagram and that's the most important thing :O.
Plus, those case structures are so darned annoying to work with....