LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting First n elements of array

Solved!
Go to solution

Hello,

For a program I am creating I need exactly 16384 data points of a current waveform.  This is a strange number but is a requirement for a VI from a driver for a function generator.  I have many csv files of waveforms that I would like to use.  However, some of the waveforms have more and some of them have less than this number of data points.  Therefore, if there are more data points, I want to cut off and extract only the first 16384 data points and use those.  When there are less, I want to just add zeros after the last data point until I have enough of them.  I then need to put this data back into a csv file as that is what the function generator VI takes as an input. What are some of the best ways to do this?

Thank You

0 Kudos
Message 1 of 7
(3,338 Views)

Hi lucasphee,

 

to ensure exactly 2^14 elements in your array you could append 2^14 zero elements to the input array, then uase ArraySubset to take the first 2^14 elements:

check.png

Best regards,
GerdW


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

Hello,

I was able to figure out my question on my own but thank you for the response!

0 Kudos
Message 3 of 7
(3,266 Views)

@GerdW wrote:

Hi lucasphee,

 

to ensure exactly 2^14 elements in your array you could append 2^14 zero elements to the input array, then uase ArraySubset to take the first 2^14 elements:

check.png


A reshape array would bot shrink and grow an array to that size:

Grow Shrink array.png

The 'fill value' can't be set though.

Message 4 of 7
(3,241 Views)

@lucasphee wrote:

Hello,

I was able to figure out my question on my own but thank you for the response!


Others could benefit from your solution. Please post it.

 

It help if you accept a (your) solution. It keeps the forum clean...

0 Kudos
Message 5 of 7
(3,240 Views)
Solution
Accepted by topic author lucasphee

To get the first n elements all I had to do was use the Array Subset and connect the number n to the length input.  The output was the first n elements of the array.

Message 6 of 7
(3,217 Views)

@lucasphee wrote:

To get the first n elements all I had to do was use the Array Subset and connect the number n to the length input.  The output was the first n elements of the array.


Thanks for posting and accepting a solution!

 

Keep in mind that this method will only shrink the array. If that is your situation, it is indeed the simplest and best solution.

0 Kudos
Message 7 of 7
(3,210 Views)