06-19-2013 08:12 AM
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...
Solved! Go to Solution.
06-19-2013 08:31 AM
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.
06-19-2013 09:04 AM
@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
06-19-2013 09:41 AM
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!
06-19-2013 09:48 AM
@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
I'll explore this method, thank you...
06-19-2013 09:49 AM
06-19-2013 10:14 AM
This could be an answer to the main title
06-19-2013 10:21 AM - edited 06-19-2013 10:25 AM
@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?
06-19-2013 10:51 AM
I was gonna say what altenbach said!
Makes me feel smart.
Just to answer the original question:
Regards
Florian
06-19-2013 01:52 PM
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.