LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract n elements in sequence from an existing array

Solved!
Go to solution

I'm looking for a way to extract first n elements from a 1D array into another array and build into a new array with the extracted elements (i.e extracting first 3 elements, then second 3 elements, and so on and building respective arrays).

 

Any suggestions? Thanks y'all

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

It is easiest if you would attach a small Vi with typical inputs as default values and expected output.

 

Your words are ambiguous. For example, what is "extract"? Copy the subarray out? or remove the extracted elements from the original array.

 

One possible solution is "reshape array" i.e. reshape into a 2D array with three columns. Then you can index these columns out if needed. Is the array size divisible by three?

0 Kudos
Message 2 of 7
(3,141 Views)

@altenbach wrote:

One possible solution is "reshape array" i.e. reshape into a 2D array with three columns. Then you can index these columns out if needed. Is the array size divisible by three?


Here's what I had in mind. As I said, it's not really clear what you want, so please clarify further.

 

altenbach_0-1586829405132.png

 

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

So I have attached a VI of 1D array with 12 inputs, but I don't know how to put random numbers in the 1D array.

 

I'm trying to copy a subarray out intervals. In the actual problem, the array would be 168 elements trying to subdivide into 7 arrays of 24 elements each. Sorry if I don't use the right words, I'm really new to labview.

 

Thanks for all your help. I really appreciate it

0 Kudos
Message 4 of 7
(3,130 Views)
Solution
Accepted by topic author wholefeed

You don't mention your use of "mean". Do you want to average N consecutive elements?

 

Here's one possibility:

 

altenbach_0-1586831669623.png

 

Message 5 of 7
(3,110 Views)

Sorry, I did want to average the N consecutive elements, but I wasn't how to make possible. How do I create that "set of three" indicator? I'm not sure what is the output is either.

 

Thanks

0 Kudos
Message 6 of 7
(3,108 Views)

you don't need that indicator, I just renamed what you already had there. It will display the currently processed three consecutive elements, but the loop will run so fast that you won't see anything interesting.

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