02-08-2022 05:00 AM
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.
Solved! Go to Solution.
02-08-2022 05:14 AM
02-08-2022 05:27 AM
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.
02-08-2022 06:02 AM - edited 02-08-2022 06:03 AM
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?)
02-08-2022 09:56 AM
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
02-08-2022 10:04 AM - edited 02-08-2022 10:08 AM
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:
02-08-2022 10:07 AM
(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....
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.
02-08-2022 10:14 AM - edited 02-08-2022 10:21 AM
@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:
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?)
02-09-2022 12:19 AM
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👍
02-09-2022 12:36 AM
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?