LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Build array

I am building an array and trying to not use build array in the loop. Question is how to have the output array with only valid values from true case and then resize the array to match. In other words in the attach VI if build array is using instead of replace array then that is the output I am looking for.

TIA

*************************************************
CLD
*************************************************
0 Kudos
Message 1 of 10
(3,849 Views)

Add a "reshape array" after the end of the for loop. The array size is the value from the array index shift register.

You can also allocate the correct array size in the first place, by counting the number of true values in the array, using the functions "Boolean to 0,1" and "Add Array Elements."

0 Kudos
Message 2 of 10
(3,845 Views)

@lvrat wrote:

I am building an array and trying to not use build array in the loop. Question is how to have the output array with only valid values from true case and then resize the array to match. In other words in the attach VI if build array is using instead of replace array then that is the output I am looking for.

TIA


I use Array Subset to shorten my array.  But it is so much easier to just use the Conditional tunnel (came out in 2012).  You can right-click on an output tunnel of a loop and choose Tunnel Mode->Conditional.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 10
(3,807 Views)

@crossrulz wrote:

But it is so much easier to just use the Conditional tunnel (came out in 2012).  You can right-click on an output tunnel of a loop and choose Tunnel Mode->Conditional.


The Conditional Tunnel isn't very efficient in LabVIEW 2012 - the actual implementation is identical to build array in a loop. It may have improved in 2013, though.

0 Kudos
Message 4 of 10
(3,773 Views)

@nathand wrote:

@crossrulz wrote:

But it is so much easier to just use the Conditional tunnel (came out in 2012).  You can right-click on an output tunnel of a loop and choose Tunnel Mode->Conditional.


The Conditional Tunnel isn't very efficient in LabVIEW 2012 - the actual implementation is identical to build array in a loop. It may have improved in 2013, though.


That information is for WHILE loops.  At least the information I was given is that FOR loops preallocate the maximum memory (since it knows what that will be) and then chop down when the loop is complete.  So for FOR loops, it works exactly the same as both options I showed above.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 10
(3,747 Views)

@crossrulz wrote:

That information is for WHILE loops.  At least the information I was given is that FOR loops preallocate the maximum memory (since it knows what that will be) and then chop down when the loop is complete.  So for FOR loops, it works exactly the same as both options I showed above.


I think it applies to FOR loops too, based on the benchmarks from this just-updated other thread http://forums.ni.com/t5/LabVIEW/Conditional-Auto-Index-Speed/m-p/239250 (which I'm sure you saw too, and I wouldn't be surprised if this thread was the reason for updating that thread). But if you participated in the 2013 Beta you may have more information than I do. In any case it appears to be fixed in 2013.

0 Kudos
Message 6 of 10
(3,739 Views)

@crossrulz wrote:

That information is for WHILE loops.  At least the information I was given is that FOR loops preallocate the maximum memory (since it knows what that will be) and then chop down when the loop is complete.  So for FOR loops, it works exactly the same as both options I showed above.


The information you were given was wrong.  Conditional indexing is just as lousy for For loops and While loops in LV12, and just as awesome in both cases in LV13.

0 Kudos
Message 7 of 10
(3,738 Views)

@nathand wrote:

I think it applies to FOR loops too, based on the benchmarks from this just-updated other thread http://forums.ni.com/t5/LabVIEW/Conditional-Auto-Index-Speed/m-p/239250 (which I'm sure you saw too, and I wouldn't be surprised if this thread was the reason for updating that thread)


This thread was the reason to update that thread.  As stated I was curious to see how the conditional index had been improved since it was one thing that people at NI had said would be addressed in 2013.  Low and behold it was.  But notice (at least in my case) how large a difference was from 2012 and 2013.  I would almost go so far to say don't use conditional index in 2012 at all.  Other methods (like OpenG) are almost as simple to do and are faster.  In 2013 however that is a different story.

0 Kudos
Message 8 of 10
(3,716 Views)

 

 


I use Array Subset to shorten my array.  But it is so much easier to just use the Conditional tunnel (came out in 2012).  You can right-click on an output tunnel of a loop and choose Tunnel Mode->Conditional.


 

 

Thanks for the suggestions,  I wrote the snippet above but the code actually checks if there is no error then build array is called, so how will conditional terminal apply to this? or if there is any other suggestion to shorten the array other than using conditional terminal? Still looking to ensure the array is built efficiently in the loop.

*************************************************
CLD
*************************************************
0 Kudos
Message 9 of 10
(3,680 Views)

To build array efficiently in loop you will have to do inplace operation. Initialize the array with max size ,fill elements inplace and then shorten the array after loop as others suggested.

For using conditional tunnel with error ,unbundle the error and pass boolean value to it.

0 Kudos
Message 10 of 10
(3,664 Views)