LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting every nth element from an array

Hi
 
I'm am trying to do something very very simple and it is annoying me that I can't find an easy logical way of doing it.  I hate dealing with strings.
 
I have a long string of comma seperated data and would like to extract every nth sub-string.
 
I have converted to an array and tryed to use the delete from array function in a for loop to try and extarct my data but am having difficulty.
 
Example:
 
I have a string: 1,2,3,4,5,6,7,8,9,10,11,12,13,14
 
I would like to extract first and then every third sub-string to give the string:
 
1,4,7,10,14
 
Hope somebody has some useful tip.
 
Ash
 
 
0 Kudos
Message 1 of 7
(6,947 Views)
Hi Ashley,

that's simple conversion and indexing... For decimation you will find a special function in the array palette, but this may have problems, when there are not enough array elements for all outputs.
Have a look at the attached vi. This solution is not perfect when it comes to big arrays, but should give you an idea!

Message Edited by GerdW on 09-08-2006 01:57 PM

Best regards,
GerdW


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

Ashley

Here is another one in LV8

David

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


@Ashley.w wrote:
I have converted to an array and tryed to use the delete from array function in a for loop to try and extarct my data but am having difficulty.


"Delete from array" will be complicated, because whenever you delete an element, the numbering of all higher elements will change.
 
One simple possibility would be to reshape the array to "n/3 by 3", then take the first column (see picture).
 

Message Edited by altenbach on 09-08-2006 05:51 AM

Message 4 of 7
(6,917 Views)
That's a great idea, Altenbach! I always just deleted items from the array in reverse order from the end to the beginning to not affect the indexing of lower elements as you go along. I never think of reshaping arrays. Somehow my brain just doesn't wrap around that so naturally, though it solves a myriad of problems elegantly! Here's a reverse order indexing solution:

Message Edited by Jarrod S. on 09-08-2006 01:10 PM

Jarrod S.
National Instruments
0 Kudos
Message 5 of 7
(6,888 Views)
Well, disregard my post. I based my answer on the forum topic (deleting every nth element) rather than the actual question, which was keeping every nth element from the original array.
Jarrod S.
National Instruments
0 Kudos
Message 6 of 7
(6,868 Views)

Many thanks for your help Guys

I used Gerd's appraoch in the end.

Thanks again

Ash

0 Kudos
Message 7 of 7
(6,807 Views)