LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to split a 1-D array into thirds

Hello,

 

I imagine this task is fairly simple but it seems there is not a function that splits a 1-D array into N arrays of X elements. For example, if my 1-D array contains [1 9 11 13 21 23 25 33 35], I would like 3 arrays of [1 9 11], [13 21 23], [25 33 35].

 

Thanks,

Micah

0 Kudos
Message 1 of 6
(3,206 Views)

reshape to 3x3 (2D) then index out the rows.

0 Kudos
Message 2 of 6
(3,205 Views)

Ok, I understand that. But what if now I dont know how may elements will be in my original 1-D array? Essentially, I am reading in a file with N rows and 12 columns. I need to be able to parse out 3 elements of the 12 columns (which I can do) but be prepared for any number of rows. 

 

Thanks,

Micah

0 Kudos
Message 3 of 6
(3,200 Views)

Can you post an example VI? 

0 Kudos
Message 4 of 6
(3,188 Views)

Altenbach's approach using Reshape Array still works, you just need to determine the appropriate array size based on the length of your 1D array (array length / 12, rounded up). Or, you could use Array Subset in a For Loop, and calculate the correct index into the 1D array (multiply the array index by 12, set the subset length to 3).

0 Kudos
Message 5 of 6
(3,185 Views)

@zerotolerance wrote:

Can you post an example VI? 


Here's what I had in mind:

 

 

If the array size is not divisible by the number of columns, you need to decide to either truncate (above code) or pad with zeroes (shown in the attached VI. LV 8.2).

 

 

Download All
0 Kudos
Message 6 of 6
(3,154 Views)