09-03-2009 04:57 AM
Fairly simple task, but too early in the morning / late in the week.... usual excuses.
I have a large array of samples (let's call it array X) that I want to split up into several smaller arrays. I have a second array (let's call it array Y) that contains the indeces to where I would like the splits to occur in the array X. These indeces will always be in ascending order.
Furthermore, I need to delete the +/-5 elements in array X either side of where the split happens. So, for each split defined in array Y, I want to delete 11 elements in array X, as well as perform the split.
Once the splits and deletions have occurred, I would like to pack the resulting fragments of array X into a 2D array.
If there are no splits (i.e. array Y is empty), then I simply repack the original array X as a 2D array with one of the dimensions equal to 1. This is shown in the attached "no_splits.png".
If there is one split, then I perform the split and deletion as described above and pack the resulting 2 parts of array X into a 2D array. This is shown in the attached "1_split.png".
In the attached PNGs, the integer array is array Y and the 1D double array is array X.
My issue occurs when there are N splits. Clearly I need to use a FOR loop, and perform the split and deletion routine N times, feeding back the remaining part of array X each time. However, I can't for the life of me get this to work - clearly I need to compensate for the offset incurred by the deletion of each successive portion of array X when using the values in array Y to index the next split location.
Any suggestions welcome. Let me know if more clarification is needed.
Dan
09-03-2009 05:45 AM - edited 09-03-2009 05:51 AM
How about something like this.
Note that the columns in the resulting 2D array get padded with 0s if the splits are not the same length. Also, if a split occurs within 5 points of the preceding split the whole column is padded with 0's.
Dave
Edit: replaced attached vi.
09-03-2009 07:42 AM
just noticed that my original vi only removes 4 points from the start of each split becasue I didn't take into account the split point itself. I've fixed this in the attached vi by adding a +1 primitive in the loop.
Dave