LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reshape array block changes row order

Solved!
Go to solution

Im using a labview VI to collect N seconds of data from an oscilloscope.

 

The while loop I am using is using indexing tunnel mode to create a 3d array  ( in my current case 55 x 2 x 5000), which i assume is 55 pages or a 2 row, 5000 column array.  Row 1 is for time data, row 2 is for voltage data and im capturing 5000 points at a time per waveform.

 

The reshape array block is taking in row as first input and page*column as second input ( in my current case its 2 rows and 55*5000 columns). When I probe the output of reshape array, I get the right size but the rows flip between pages. For example, the data that was in page 0 had time data on row 1, voltage data on row 2; the data that was on page 1 has voltage data on row 1, time data on row 2.

 

The other issue is my time vector is in the wrong order, so if i am collecting for 1 second. The reshaped array will go 0- 0.02. 0.5 - 0.52, then back to 0.02 to 0.022, and so on.

 

attached are screenshots of the 3d and reshaped array for clarity.

 

How can I fix this? Im not sure why reshape is behaving this way. How does it reshape 3d arrays? im assuming page by page, row by row

 

0 Kudos
Message 1 of 7
(2,008 Views)

Please attach a VI containing some default data.

 

Reshape array will keep the elements in memory order, so you need to be fully aware of the way 3D arrays are arranged linearly in memory. I am sure there is a logical explanation.

Message 2 of 7
(1,980 Views)
Solution
Accepted by abashat2

I am not sure exactly how to describe the way the reshape array works, but here is an example:

This is a 3 page, 2 row, 3 column array.  If it is reshaped into a 1-D array (which matches the memory layout described here: http://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/how_labview_stores_data_in_memory/ ), it is

[0] page 0, row 0, col 0

[1] page 0, row 0, col 1

[2] page 0, row 0, col 2

[3] page 0, row 1, col 0

[4] page 0, row 1, col 1

[5] page 0, row 1, col 2

[6] page 1, row 0, col 0

[7] page 1, row 0, col 1

[8] page 1, row 0, col 2

[9] page 1, row 1, col 0

...

[17] page 2, row 1, col 2

For reshaping into a 2-D array with row size and column size, it will reshape it as if it was one big 1-D array into [column size] chunks - if you try to use 2 rows and 9 columns:
[0][0] page 0, row 0, col 0

[0][1] page 0, row 0, col 1

...

[0][8] page 1, row 0, col 2

[1][0] page 1, row 1, col 0

...

[1][8] page 2, row 1, col 2

 

To avoid this issue, you can change the order of the dimensions - in this case, you can rebuild the 3-D array by indexing out each row's 2-D array and building those back into a 3D array.  This can be reshaped into the 2-D array you want (see the snippet below).
Reshape Array.png

You could also index down to single-points and rebuild the array using auto-indexing and auto-concatenating terminals in nested for loops - no call to reshape array needed.

Message 3 of 7
(1,966 Views)

Ok. Following your suggestion I can see what's happening. I think its what the other commenter was saying its easier to interpret when i can see the arrays. 

 

so due to the way reshape accesses and reads data, what is occurring is that row 2 is read in as row 1 because I am asking for a size that is bigger than the column*row size for a page, so row 2 gets concatenated to row 1 which explains what I was seeing. 

 

I think, i need to follow the other commenter's suggestion and do this a bit more manually by indexing into the 3D array and building a new 2D array. 

0 Kudos
Message 4 of 7
(1,956 Views)

So can you explain what result you would expect from your attached VI? (once you correctly modify it so it gives the same result with succesive runs)

0 Kudos
Message 5 of 7
(1,946 Views)

The correct way would probably be to not even create a 3D array. Your final 2D array size is fully known from the start, so initialize that, keep it in a shift register, and just replace relevant parts with data in the innermost acquisition loop.

0 Kudos
Message 6 of 7
(1,939 Views)

@abashat2 wrote:

The while loop I am using is using indexing tunnel mode to create a 3d array  ( in my current case 55 x 2 x 5000), which i assume is 55 pages or a 2 row, 5000 column array.  Row 1 is for time data, row 2 is for voltage data and im capturing 5000 points at a time per waveform.

 


If the time axis is regular, you probably don't even need to store it (except for a scalar dt, assuming t0=0).

 

If you really want to store time|data value pairs, consider complex data (RE=time, IM=data), eliminating one dimension.

 

What is your LabVIEW version? Do you have the concatenating tunnel option?

 

Can you attach an example that more closely resembles your original problem (just with much smaller dimension, but including simulated time and  data)?

0 Kudos
Message 7 of 7
(1,935 Views)