LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2D to 3D array

Solved!
Go to solution

I have a 2D array of integers such as

 

1,1,1

1,2,2

1,3,3

2,1,0

2,2,0

3,3,0

 

I want to create a 3D array such that

page0 =

1,1,1

1,2,2

1,3,3

 

page1=

2,1,0

2,2,0

 

page2=

3,3,0

 

I am not sure what is the best approach to doing this.

 

0 Kudos
Message 1 of 14
(4,911 Views)

Impossible. All pages must be 2D arrays of the same size.

 

(You could make a 1D array of clusters where each cluster contains a 2D array, representing a page.)

Message 2 of 14
(4,910 Views)

I can live with pages of equal sizes.

For the above data set, the 2D array will be 3x3.

 

Is there a way to do this?

 

0 Kudos
Message 3 of 14
(4,902 Views)

Does the first element (minus 1) represent the page?

What if there are more than three rows with the same page number?

Are the rows always sorted by the first element?

 

I would initialize a 3D array with all zero (or even NaN), place it in a shift register, then loop over the 2D input array, replacing one page row at a time.

0 Kudos
Message 4 of 14
(4,895 Views)
Solution
Accepted by topic author nyc_(is_out_of_here)

Split your 2D-array at row indices 2 and 4, giving you 3 new 2D-arrays. pass these on to a 'build array' (right click and make sure it does not concatenate inputs), giving you a 3D-array.

 

If you dont want each page of the same size, bundle each 2D-array into a cluster before building the new array, effectively giving you a 1D-array of clusters containing 2D-arrays, as Altenbach suggested.



CLA
www.dvel.se
0 Kudos
Message 5 of 14
(4,893 Views)

@M_Peeker wrote:

Split your 2D-array at row indices 2 and 4, giving you 3 new 2D-arrays. pass these on to a 'build array' (right click and make sure it does not concatenate inputs), giving you a 3D-array.

 

 


Visually I can see that I need to split my 2D-array at row indices 2 and 4, but I want to do this programmatically.

 

With another set of data, the row indices may be at 5 and 7.

 

Is there a fast way of doing this?

0 Kudos
Message 6 of 14
(4,887 Views)

@altenbach wrote:

Does the first element (minus 1) represent the page?

What if there are more than three rows with the same page number?

Are the rows always sorted by the first element?

 

I would initialize a 3D array with all zero (or even NaN), place it in a shift register, then loop over the 2D input array, replacing one page row at a time.


No, the first element does not repesent the page number. I can see how they can be construed that way though.

 

The rows are already sorted when they get to this VI I am trying to write.

 

0 Kudos
Message 7 of 14
(4,884 Views)

Not fast maybe, but this should work, providing you know the indices where to split (they should be 3 and 5 in your example it turns out).Split2DArrays.png



CLA
www.dvel.se
0 Kudos
Message 8 of 14
(4,868 Views)

If the row to page/row mapping is constant, just use diagram constants, e.g. as follows.

 

 

0 Kudos
Message 9 of 14
(4,867 Views)

nyc wrote:With another set of data, the row indices may be at 5 and 7.

OK, so the output array is not necessarily 3x3?

I think all you need to do is use a FOR loop with N=number of pages.

Inside the FOR loop, take the various subsets.

The 3D array will automatically pad to the largest 2D array subset once you autoindex at the output tunnel.

Message 10 of 14
(4,863 Views)