05-30-2011 09:43 AM
Say I have an array of 500 elements and would like to perform analysis on every 10 elements i.e. perform analysis on elemens 0-9, then on 10-19, then on 20-29 etc. etc. what would be the best way about doing this.
I was thinking about splitting up the array into a number of subarray's but the decimate 1D array function doesn't maintain the order of the elements in the original array. Is there any other function that can be used to achieve this?
I understand I could use a loop of some sort to iterate through the array and perform analysis every 10 elements but the array could be quite large and I want to do this as efficiently as possible.
Any ideas?
Strokes
Solved! Go to Solution.
05-30-2011 10:05 AM
The Array Subset in a loop is probably best. This does not change the allocation of memory for the main array and only allocates one 10-element subarray space which can be reused.
Do you ever need the entire array later for something else or do you just use the subsets? Do you need more than one subset at a time? A complete description of what you are trying to do would help us give you good answers.
Lynn
05-30-2011 10:21 AM
@johnsold wrote:
The Array Subset in a loop is probably best. This does not change the allocation of memory for the main array and only allocates one 10-element subarray space which can be reused.
Do you ever need the entire array later for something else or do you just use the subsets? Do you need more than one subset at a time? A complete description of what you are trying to do would help us give you good answers.
Lynn
I don't necessarily need the entire array later but it might be nice to have if I want to plot the data. No i'll never need more than one subset at a time.
My objective is simple enough, I'll stream parsed data from a device into an array. When the data stops streaming, i'll have an array of however many values depending how long the data is streaming for. I'll then analyze a certain subset of the array maybe 10, 15 or 20 elements at a time.
I think what you've described above is a solution, it's certainly something i'll experiment with anyways so thanks for that.
Strokes
05-30-2011 10:36 AM
Check this out
05-30-2011 01:25 PM
05-30-2011 04:31 PM - edited 05-30-2011 04:32 PM
@Amd1480 wrote:
Check this out
I have the feeling that the constant resizing of the array inside the shift register might cause more memory allocation that you would like.
I would recommend a simple "reshape array" or "array subset" as has already been suggested. Here are the two alternatives.
If the array size in not divisible by the subeset size, these example will ignore the incomplete tail. (It would be a trivial change to instead process it.)