LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Slice and sum a 2D-array

Solved!
Go to solution

My original problem is the following: I have a 2D array containing 64 measurements. Each measurement has a fixed amount of points (40000 points). For the sake of analysis, I need to add all 64 measurements together and then divide the result by 64.

 

Ultimately, the problem can be simplified as a 1D array (so a single column) having 64*40000 rows, which represents 64 datasets with the same size (40000 points). Finally, the resulting sum of the subsets will be divided by the number of subsets (64)

My initial thought was to make a For Loop containing a Shift Register and to use the "Array Subset" to extract the data from the original 2D array, but for some reason, it is not working. I worked on a Minimal Working Example to find a solution for my problem, but I have been unsucessful so far, as when I was testing the "Array Subset" function, it did not provide me with the data I was expecting. If there is an easier way to do it, I would be very happy to learn it!

 

Your help would be very welcome. 

0 Kudos
Message 1 of 20
(745 Views)

If each measurement is in a row (i.e. 64 rows & 40000 columns), then:

paul_a_cardinale_0-1721110682359.png

 

If each measurement is in a column (i.e. 40000 rows & 64 columns), then:

paul_a_cardinale_1-1721110765664.png

 

Message 2 of 20
(738 Views)

Hi Flonares,

 

didn't we answer this question already yesterday?

Best regards,
GerdW


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

Hi Paul, thanks for your reply. I realized that some important information was missing.

 

The array is only composed of two columns with 64*40000 rows. Ideally, the problem can be reduced to a 1D array with 64*40000 points. So one would need to divide the 1D array into 64 equal parts and sum them together.

0 Kudos
Message 4 of 20
(727 Views)

Hi Gerd, 

 

I believe this is a different problem, which is to slice a 1D array into 64 identical bits and sum them all together. I will edit the initial question to add more relevant info.

 

Cheers,
Fl0

0 Kudos
Message 5 of 20
(723 Views)

Gerd,

 

I understand your reply now. I do have part of yesterday solution in the answer because in my actual data, the first subset has more data points - which I wanted to discard -, so I opted to reverse the data to be easier to code and discard the last bit of data 🙂 - it´s half of the solution to another problem I did not advertise. I shared the entire VI, so it had that bit of code in it.

0 Kudos
Message 6 of 20
(714 Views)

Hi Flonares,

 


@Flonares wrote:

The array is only composed of two columns with 64*40000 rows.


So you have an input array of 2 columns and 2560000 rows?

 


@Flonares wrote:

Ideally, the problem can be reduced to a 1D array with 64*40000 points. So one would need to divide the 1D array into 64 equal parts and sum them together.


How do you "divide" the array into equal parts?

I guess you want to split that array of 2560000 elements into 64 subsets of 40k elements:

  • use a FOR loop iterating 64 times
  • place ArraySubset inside and calc the start index for the current subset of 40000 elements
  • use ArraySum on each subset

(Unfortunately I cannot open your VI right now, I prefer LV2019.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 20
(704 Views)

Gert,

 

Can you provide me with a Minimal Working Example? I´m fighting with the Array Subset but I am not managing to get the desired result.

 

Cheers,

Fl0

0 Kudos
Message 8 of 20
(660 Views)

Hi Flonares,

 


@Flonares wrote:

I´m fighting with the Array Subset but I am not managing to get the desired result.


ArraySubset only has 3 inputs: which of them is giving you problems???

 

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 20
(637 Views)

Hi Gerd,

 

the index and the length are giving me issues. I made a small example to test it. It seems that the index controls the row index and the length the actual length of the the row. So it seems that I need to transpose my data in order to use it correctly. But then I noticed that if I change the index, then it selects two rows instead of just selecting the indicated index row. Maybe I am not understading full well the behaviour of the VI. I tried reading on the NI help webpage for more information but it didn´t shed more light on the behaviour.

 

Cheers,

Download All
0 Kudos
Message 10 of 20
(617 Views)