LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create 3d array from incoming 1d succession of data and arrange in zig-zag pattern

Hello!

I would like to create a 3d array using the iteration count of the while loop.

i=    11 10 9 8 7 6 5 4 3 2 1 0   (1d)

 

2d:  

  0   1  2

  5   4  3

  6   7  8

11 10  9.

 

3d: please see picture.

 

I started by creating an initial array of xcol*yrows.

But that is wrong because the while loop keeps  initializing the 'mother array' with the element 0.

The VI should return 

0 1 2

3 4 5 

6 7 8

9 10 11 and it does (highlight execution) but overwrites the values and only keeps the last (11).

Questions:

1-How can we create an x*y array, from an incoming 1d array, when we know the rules of creating it:

row index= [i/x] = the integer part of iteration index devided by the number of columns;

column index=i mod 4= 01230123...

2-For the zig-zag filling of columns: if

i is: 11 10 9 8 7 6 5 4 3 2 1 0

c       3   2 1 0 0 1 2 3 3 2 1 0 (column index)

where 4 is the number of columns. So, if i=0 to m*n, n=nr. of columns, m=integer multimple of n,  then

i =  0 1 2 3 4 n-1   n     n+1..  2n-2  2n-1    2n  2n+1 ...3n-1 3n...  mn-1

c=  0 1 2 3 ...n-1   n-1  n-2 ... 1       0         0    1           n-1   n-1... ?

?= 0 if m is even 2,4..

  =n-1 if m is uneven 1,3...

How can we programatically create this pattern 0 1 2 ...n-1 n-1 n-2 ..1 0 0 1...n-1 ...

I was thinking of a case structure controlled by the unevenness of the ration r=i/x: if r=0,2,4.. then use the remainder(0123 0123) to set the index BUT if r=1,3,5... use the modulo x complement : take 0 1 2 3 (if x=4), convert to binary, 00,01,10,11 , deny the numbers (I don't know the english word for this operation) by subtracting them from 11 => 11,10,01,00, convert binary to decimal nr=> 3,2,1,0 and it should work(I think...I'll try it after finishing writing this post).

Is there  a more elegant solution (assuming what I wrote above is also a solution) to making this pattern? 

Thank you!

Download All
0 Kudos
Message 1 of 13
(4,396 Views)

I'm not sure if I'm understanding correctly but it sounds like you just want to use Reshape Array.

Can you collect all of the 1-D data and then reshape at the end or is it a requirement to pack your array an element at a time?

EDIT: For your actual program, you want to initialize the array outside of your while loop. Currently you are reinitializing it to all zeroes every iteration.

0 Kudos
Message 2 of 13
(4,365 Views)

Does it have to be fast?

 

 Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 3 of 13
(4,356 Views)

Thank you for the replies !

The readings are coming one by one which is why I was using the while loop iteration counter to mimic the reading coming from the device.

Every second I am sampling information from a device; it comes in the form of a 1x1 array containing a number( like a brick).

I would like to use these bricks to create a wall and then the next wall until a cube is completed (or any rectangular cuboid).

i: 0  1  2  3  4  5  6  7  8  9   10    11        (package index)

t:  1   2  3  4  5  6  7  8  9 10    11     12   (time, seconds)

I know from the start x,y the number of rows and columns I must fill and the order in which they must be filled but the values are coming in succession and must be guided to the appropriate coordinates.

I would like to fill/build the array one brick at a time, as they arrive, because I will also need to plot it in real time, so each value from the 3d array must correspond to the position of the probe; the probe moves in the manner described above(zig-zag) .

 

 

0 Kudos
Message 4 of 13
(4,316 Views)

How could I do the boolean NOT operation for modulo n numbers?

for a U8 number: modulo 4, take nr, convert to bool string, not, => string, modulo 4 => NOT nr

0,1,2,3=>3,2,1,0

 

but for modulo n ,where n is not a power of 2 like 4 is, it doesn't work by converting it to boolean string and NOTing it.

How do I NOT a modulo 6 number for example:

0,1,2,3,4,5=> 5,4,3,2,1,0 ?

 It's 5-x , x=0:5

so n-1-x.

Silly question, I am sorry, ignore this.

0 Kudos
Message 5 of 13
(4,292 Views)

This fills the 2D array with a random number in the order you've described:

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 6 of 13
(4,273 Views)

[deleted]

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 7 of 13
(4,263 Views)

Very nice what you did with the calculus of the columns !

I will try to implement that in my original design(the big while loop which will encompass the entire program) and get rid of the for loop;

as I said, I will use the data in the table to plot it as it is being received.

Thank you, jcarmody !

0 Kudos
Message 8 of 13
(4,216 Views)

is there a way to not use the initial array, the one filled with zeros?

I mean: could we take the elements coming from the random generator, convert them to 1x1 arrays and take the arrays one by one and concatenate them in the desired shape without the need of a preexisting array in which to insert the new values?

0 Kudos
Message 9 of 13
(4,199 Views)

@TibiG wrote:

is there a way to not use the initial array, the one filled with zeros?

I mean: could we take the elements coming from the random generator, convert them to 1x1 arrays and take the arrays one by one and concatenate them in the desired shape without the need of a preexisting array in which to insert the new values?


You could if you built all of your rows in one loop and only added full rows to the 2D array.  The rows must be the same size when you add a 1D array to a 2D array.

 

Are you concerned that you won't know how large to make the array at the beginning?  That concern is handled by occasionally building the array, rather than constantly building the array.  Constantly building an array can become a memory issue later.

 

If you're concerned that the zeros can be mistakenly used in place of valid data, you can initialize the array with NANs (or something).

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 10 of 13
(4,178 Views)