LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

converting a 2D array to a 1D array

hi guys nd gals, this program converts a 2D array to a 1D array. it works fine but i dont understand how is it working or the logic behind it. kindly help

thanks

0 Kudos
Message 1 of 20
(7,693 Views)
i need urgent help please....
0 Kudos
Message 2 of 20
(7,688 Views)

Hi irish_sun,

 

first:

this vi is converting the U32 values to bit arrays and appends them to form a 1d array (aka "bitstream"). Both "insert into array" functions are used with the shift registers to form this 1d array.

 

2nd:

There's a lot of "rube goldberg" and other "non-optimal" code.

-To check booleans for "equal to false" is like a boolean "not" operation. The result of this operation is again inverted by assigning zero to true and 1 to false. A simple "boolean to number" conversion will do here too...

- to use an "insert into array" with an index of array size is the same as using "build array" with correctly wired inputs...

Message Edited by GerdW on 05-12-2009 09:54 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 20
(7,679 Views)

irish_sunset wrote:

 it works fine but i dont understand how is it working or the logic behind it.


I don't want to understand it, because (as Gerd already mentiond), the code is inefficient and contains 90% garbage. (for example the upper right FOR loop is not needed to determine the size(s), that value is fully determined by the datatype of the 2D array).

 

Can you attach the actual VI? I am sure all this could be done with a few atomic operations with code the size of a postage stamp. 😄

Message 4 of 20
(7,647 Views)

Okay, I spent way more time than I should have looking at this. The vi you showed does more than convert a 2D array to a 1D array (if only it were that easy). Unfortunately, it does just about everything inefficiently. I took a crack at creating a more efficient version. I also wanted to illustrate that the code you showed actually expands the storage/memory required for the input array by 800%! If that is really a requirement, than technique 1 duplicates the output, but a little bit faster. If storing each bit in 1 bytes is the the desired effect, technique 2 shows one way to make something similar, but using only the space require of the original.

 

Unfortunately, I couldn't think of a really fast/efficient way of reversing the order of the bits in the output for technique 2 (maybe one of the bit twiddling experts could chime in). So, looking at the two outputs, you can see that T1 store 1 bit in each bytes, and that they are in the opposite order from T2. That is, if you look at the first element of T2, it matches the first 8 elements of T1 if read backwards.

 

I guess the question I have is, is T1 really what you are trying to do?

 

A quick walkthrough of T1 follows:

1) determine the number of elements in Array by getting the size and multiplying the size of each dimension by one another (3 by 3 array has 3*3=9 elements).

2) Reshape the array into 1 dimension.

3) for each 32bit element of the array, convert each bit to a boolean and then cast each boolean element to a U8 (this is where each bit gets expanded into requiring 8bits)

4) Again, determine the number of elements in the 2D array of U8s and reshape the array back into 1dimension

 

 

Chris

 

 

 

Ah, Altenbach is here now. Maybe he can explain how to reverse the order of the bits. I'll attach the vi saved in 8.6 if anyone else wants to play with it. The original code was recreated in the disabled case.

 

Message Edited by C. Minnella on 05-12-2009 04:59 PM
Download All
Message 5 of 20
(7,641 Views)

Here's another possibility that probably does something similar, if not equal. 😮 Modify as needed. 😉

 

Message Edited by altenbach on 05-12-2009 02:08 PM
Message 6 of 20
(7,634 Views)

C. Minnella wrote:

Ah, Altenbach is here now. Maybe he can explain how to reverse the order of the bits.


To reverse the bits in a U8 array, I would use a 8 bit lookup table as follows.

 

 

The LUT is of course calculated at compile time and folded into a constant, no penalty there. You could also run it once and manually turn it into a diagram constant. (Note that the "boolean array to number" has the output configured to be U8 (LabVIEW 8.6 only)).

 

Still, it makes no sense to do all that, of course!

Message Edited by altenbach on 05-12-2009 02:29 PM
Message 7 of 20
(7,621 Views)

Ah, neat. I totally didn't know that I could change the datatype of the boolean array to number. Kudos!

 

Chris

0 Kudos
Message 8 of 20
(7,579 Views)

Hi Chris,

 

you mean you already used the "number to boolean array" function but didn't recognize the inverse function right next to it? Smiley Wink

Message Edited by GerdW on 05-13-2009 04:15 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 20
(7,568 Views)

 

 

I guess chris wasn't aware of the fact that we can configure the primitive for a specific output representation. In LabVIEW 8.2 and earlier, the number output was fixed at U32. Now we can cofigure it so it e.g. spits out U8 (as needed here) so we don't need to convert later.

 

Very useful!

 

 

Message Edited by altenbach on 05-13-2009 08:44 AM
Message 10 of 20
(7,547 Views)