LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract every nth element from an existing 1d array

Solved!
Go to solution

Ive reviewed a few forums related to this question, but not exactly what i need.

 

I'm looking for a way to extract every nth element from a 1D array. The data in the array is very large so decimate function would not be helpful since i need to extract every 200th element from the array, and then build a new array with all of the extracted elements. 

 

Any suggestions? Ive tried a few things and am feeling very stuck since none of them worked.

 

0 Kudos
Message 1 of 18
(11,399 Views)

nth aray element.png

Message 2 of 18
(11,392 Views)

BowenM beat me to it.

 

Lynn

 

Extract nth.png

Message 3 of 18
(11,381 Views)
Solution
Accepted by libbyherself

For older LabVIEW versions:

check.png

(and allowing the compiler to set output array size at FOR loop start…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 18
(11,380 Views)

Also Reshape Array, then use Index Array to get the row or column of interest.

0 Kudos
Message 5 of 18
(11,364 Views)

Thanks for your fast repsonse, i believe this is what im looking for except it wont allow me to wire my array through the loop like you have, error: wire connected to an undirected tunnel appears.... any suggestions?

0 Kudos
Message 6 of 18
(11,360 Views)

Thanks for your fast repsonse, i believe this is what im looking for except it wont allow me to wire my array through the loop like you have, error: wire connected to an undirected tunnel appears.... any suggestions?

0 Kudos
Message 7 of 18
(11,348 Views)

never mind got it, thanks!!

0 Kudos
Message 8 of 18
(11,345 Views)

I think that RavensFan's suggestion of using Reshape Array is usually the best for these kinds of operations.  Note that when indexing you have to wire a zero into the columns index terminal, or the column indexing will be disabled.

 

Every_nth_Element__Reshape_Array.png

 

Is there any better way to do a roof() function on the array and n?



Message 9 of 18
(11,323 Views)

@libbyherself wrote:

The data in the array is very large so decimate function would not be helpful since i need to extract every 200th element from the array, and then build a new array with all of the extracted elements. 


It also really depends what kind of noise and frequencies are in the data and what the data reprensents. In the worst case, just taking every nth element might give you all kinds of alias frequencies, distorting your data. You might want to do some filtering. Even just taking the average of chunks of 200 points might give you cleaner, less noisy data. (example)

0 Kudos
Message 10 of 18
(11,305 Views)