10-24-2013 08:29 PM
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
10-24-2013 09:00 PM
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."
10-25-2013 06:38 AM - edited 10-25-2013 06:39 AM
@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.
10-25-2013 11:47 AM
@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.
10-25-2013 01:42 PM
@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.
10-25-2013 01:48 PM
@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.
10-25-2013 01:49 PM
@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.
10-25-2013 04:32 PM
@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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
10-28-2013 11:05 AM - edited 10-28-2013 11:10 AM
crossrulz wrote:
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.
10-28-2013 11:21 AM - edited 10-28-2013 11:22 AM
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.