From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How would you remove every 6th (or nth) element of an array?

Solved!
Go to solution

Thanks to altenbach (see http://forums.ni.com/t5/LabVIEW/How-can-I-restructure-an-unfavourable-2D-array-format-to-1D/m-p/2463... I've managed to arrange my 2D array data into a 1D column. Unfortunately the format of the data files is tab delimited, which wouldn't be a problem, except there is an extra tab on the end of each row, generating a zero for every 6th element in the column. Having reshaped the original 2D array into a 1D array, how can I remove all these zeroes? Attached is a sample data file of the original 2D data for one measurement and the 1D corrected version I've managed to generate for all data; note the 2D raw data file also has a header and footer, which I've been able to remove myself...

Download All
0 Kudos
Message 1 of 12
(6,132 Views)

I feel like you should be able to create a more flexible for loop using a while loop. You could start at the last index of your array, find the first multiple of n below it (with adjustments for the initial index as necessary), and then decrement by n until your value becomes less than zero. I don't have access to LabVIEW at the moment, but the pseudocode for this would look like this, assuming a 20 element array where you want to delete every sixth element.

 

Get Array Size = 20

 

Finding the last multiple of six index (the -1 is because indexing starts from zero)

index Array Size mod 6 * 6 - 1  = 17

 

While index > 0 

Delete Array(index)

index - 6

 

 

I'm not sure that this is the most elegant solution, but it should work.

0 Kudos
Message 2 of 12
(6,113 Views)

@apg504 wrote:

Thanks to altenbach (see http://forums.ni.com/t5/LabVIEW/How-can-I-restructure-an-unfavourable-2D-array-format-to-1D/m-p/2463... I've managed to arrange my 2D array data into a 1D column. Unfortunately the format of the data files is tab delimited, which wouldn't be a problem, except there is an extra tab on the end of each row, generating a zero for every 6th element in the column. Having reshaped the original 2D array into a 1D array, how can I remove all these zeroes? Attached is a sample data file of the original 2D data for one measurement and the 1D corrected version I've managed to generate for all data; note the 2D raw data file also has a header and footer, which I've been able to remove myself...


Wouldn't it be easyer to remove the extra tab at the end of each line of the data file instead?

 

Ben64

 

Remove tab at end of line.png

Message 3 of 12
(6,091 Views)

Well, if LabVIEW could do that, otherwise I've got 72 data files with around 1600 lines with tabs at the end. I don't have that kind of time!

0 Kudos
Message 4 of 12
(6,073 Views)

@ben64 wrote:

@apg504 wrote:

Thanks to altenbach (see http://forums.ni.com/t5/LabVIEW/How-can-I-restructure-an-unfavourable-2D-array-format-to-1D/m-p/2463... I've managed to arrange my 2D array data into a 1D column. Unfortunately the format of the data files is tab delimited, which wouldn't be a problem, except there is an extra tab on the end of each row, generating a zero for every 6th element in the column. Having reshaped the original 2D array into a 1D array, how can I remove all these zeroes? Attached is a sample data file of the original 2D data for one measurement and the 1D corrected version I've managed to generate for all data; note the 2D raw data file also has a header and footer, which I've been able to remove myself...


Wouldn't it be easyer to remove the extra tab at the end of each line of the data file instead?

 

Ben64

 

Remove tab at end of line.png


I'll explore this method, thank you...

0 Kudos
Message 5 of 12
(6,064 Views)

The code I added in my previous post will do that for you. Have you try it?

 

Ben64

0 Kudos
Message 6 of 12
(6,063 Views)

This could be an answer to the main title

 

Untitled.gif

 

 

_____________________________________
www.azinterface.net - Interface-based multiple inheritance for LabVIEW OOP
Message 7 of 12
(6,049 Views)
Solution
Accepted by topic author apg504

@apg504 wrote:

Unfortunately the format of the data files is tab delimited, which wouldn't be a problem, except there is an extra tab on the end of each row, generating a zero for every 6th element in the column. Having reshaped the original 2D array into a 1D array, how can I remove all these zeroes?


Well, the order of operations is important here. What if you simply delete the last column of the array before reshaping?

 

Message 8 of 12
(6,040 Views)

I was gonna say what altenbach said! Smiley Wink

Makes me feel smart.

 

Just to answer the original question:

remove nth element.png

 

Regards

Florian

Message 9 of 12
(6,026 Views)

Florian.Ludwig, I wonder how Reshape Array works with memory alocation? If it uses the same phisical memory, your solution is better than my. However, if I understand the manual literally ("... reads the array data in memory from left to right, row by row ... adjusts the array data in memory ... "), the memory is realocated.

_____________________________________
www.azinterface.net - Interface-based multiple inheritance for LabVIEW OOP
0 Kudos
Message 10 of 12
(5,997 Views)