07-07-2009 08:20 AM
Hi,
I'm relatively new to Labview and am having trouble with large arrays. I'm using Win32 IO functions to read a 8MB file into Labview and this products a large U8 array. I want to produce a binary array containing the second bit of each byte in this array. For example:
File:00000000 00000010 00000000 00000010 00000010
Binary array: 01011
At the moment I'm using a For Loop and clearly its very inefficient. Is there any way to do the above in a relatively short period of time?
I used a subvi containing a For Loop and enabled Reentrant execution but this isnt very fast either.
Any help would be greatly appreciated,
John
07-07-2009 08:33 AM - edited 07-07-2009 08:34 AM
I would use Build Array Function instead of Insert into Array. It makes the code a little bit leaner.
Why not pack the boolean values into a boolean array instead of converting them back to integers and storing them in an integer array?
More efficient would be to initialize an array and use Replace Array Subset inside the loop. Since you can determine the size of the array before the loop starts (you have the Length control defining the size of the array you want to work on), you can initialize an array of that size one time, then replace elements within the loop. This is more efficient for large arrays as LabVIEW will not have to spend any time shuffling the array around in memory as it grows in size.
07-07-2009 08:43 AM
John,
There are probably a million ways to get this done and you will have to experiment a lot to find one that is really fast and furious! I attached one suggestion.
-cb
07-07-2009 08:46 AM
07-07-2009 08:50 AM - edited 07-07-2009 08:52 AM
Hi John,
You can use boolean operators on integers. No need to convert to boolean array. To extract a bit, just AND with a constant with the bit in question set. Also, you don't need the loop.
See attached example.
The quotient & remainder is one way to scale the resulting array to 1. Without this you'd get an array of 0's and 2's.
Hope this helps,
Daniel
EDIT: Sorry for repeating 10degree, I was distracted while writing the message
07-07-2009 08:58 AM - edited 07-07-2009 08:58 AM
Thanks for the help. I'll implement all the solutions and Profile them to get the best result. I didn't expect such a fast response!
@dan_u thats really useful.
Edit:Typo
07-08-2009 07:21 AM