LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Split 1D array to multiple columns

Solved!
Go to solution

Hey,

I'm trying to split my 1D array which has 2000 samples into multiple columns. For Eg. My input array has one column of data with 2000 samples, my output array should have 1 to 50 samples in the first column, then 2 to 51 samples in the second column, and 3 to 52...,

 

Thanks. 

0 Kudos
Message 1 of 10
(3,540 Views)

Hi feller,

 

you should try to use the ReshapeArray function…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(3,537 Views)

Thank you for the quickest reply. Can you please tell me the dimensions I should give in reshape array function to get the desired array.

 

Thanks in advance.

 

0 Kudos
Message 3 of 10
(3,530 Views)

Hi


@feller97 wrote:

Can you please tell me the dimensions I should give in reshape array function to get the desired array.


When you have 2000 elements in your 1D array and want to achieve a 2D array of 50 elements per row (or column) you should create an array of 50 × (2000/50) elements…

 

(Simple math, right?)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 10
(3,520 Views)

Thanks again. But your solution divides my array as 50 samples per column. But what am expecting is. For Eg:

Input Array

1

2

3

4

5

6

7

8

9

Output array

1,2,3,4,5

2,3,4,5,6

3,4,5,6,7

4,5,6,7,8

.

.

.....

Thanks

0 Kudos
Message 5 of 10
(3,488 Views)

Hi feller,

 


@feller97 wrote:

But your solution divides my array as 50 samples per column. But what am expecting is. For Eg:


Sorry, misread your problem description…

 

In this case simply use ArraySubset in a loop:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(3,482 Views)

(Note that LabVIEW does not have a concept of columns vs. rows for 1D arrays. So you just have a 1D array.)

 

You also need to to decide what to do if the number of elements is not divisible by the number of columns, requiring padding of the last row.

 

See if this can give you some ideas....

 

altenbach_0-1644336379678.png

 

Also note that reshape array does not touch the memory order of elements, so you might need to transpose at the end in different situations.

0 Kudos
Message 7 of 10
(3,477 Views)
Solution
Accepted by feller97

@feller97 wrote:

Output array

1,2,3,4,5

2,3,4,5,6

3,4,5,6,7

4,5,6,7,8

 


Sorry, I got distracted by the existing answers. Yes, "array subset" is the correct tool here:

 

altenbach_0-1644336854883.png

 

Don't forget the +1 for N if using Gerd's code.

 

(On a side note, you are not really splitting the 1D array, but create a highly redundant 2D array that has many elements in duplicate. There is probably a better word than "splitting". for all this. For such sliding window operations, you might think about doing the subset calculation right there in the loop instead of building up these huge redundant data structures. Can you tell us a little bit more about what you are trying to do from a larger perspective?)

0 Kudos
Message 8 of 10
(3,473 Views)

Thank you Mr. AltenBech

Thank you Mr. GrerdW 

Both your solutions did work👍 by "adding +1 to N".

 

Coming to Mr.AltenBech's Question "Can you tell us a little bit more about what you are trying to do from a larger perspective?"

 

yes!

 

This sliding window operation is one of the steps in implementing the algorithm that am working on currently. In this redundant 2D array, I consider every row as "one window". So after this, I've to form two arrays(Xa and Xb) out of the solved 2D array. For example, I'll have to take the first 25 samples from the first window (row), keep it as Xa, reverse that 25 samples(Xa), and keep it as Xb. Take cross-correlation for Xa and Xb to get Z(output from cross-correlation).

 

Continue this process for every window(row) to get Z, Z1, Z2... Zn. Finally, store the Z vector in a TDMS file Format.

 

Thank You👍

0 Kudos
Message 9 of 10
(3,441 Views)

So what I meant is that you really never need that huge 2D array in memory (as you describe in you first post). All you need is a single loop as shown and do the cross correlation between the subset and its reverse right there, reusing the same (much smaller) memory over and over.

You talk about "Z vector" (1D array?) but the output of the cross correlation is already a 1D array. Is there additional data reduction/processing or is the final result a 2D array again?

 

Side note: You could even parallelize the operations to take advantage of multiple CPU cores.

 

Do you have a website that describes the algorithm?

0 Kudos
Message 10 of 10
(3,434 Views)