LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

overwriting array is not ok

Hi all,

I have a problem where I am running a couple of loops that write string
data into an array but then it writes new data over the last in the same
array. I don't know how to create new arrays for each row of data
coming out of the same loop. Below is a description of my program &
problem.

I have a long string of test data that I have parsed down using "match
pattern" vi to remove the header info and the column names. For each
row of data, I need to remove the row names; I have done this with a FOR
loop/shift register and again used the "match pattern" vi.
Within the FOR loop:
To detect the end of the row, I have matched pattern to \r\n and sent
the "before substring" row of data into a shift register in another FOR

loop. I then match pattern for three spaces between each piece of data
and send this data out to an array. Then, the outer loop takes the
"after substring" data and again parses it to the end of row and sends
it back into the inner FOR loop that matches patter for the three
spaces. This continues until all data in string has been handled ( I
will always have the same number of data to deal with).

The big problem is that I always end up with only the last row of data
in the array. I know I will need a 2D array but I cannot figure out how
to do this and index each row into it, given the rest of my program.
The end goal is to end up with a tab delimited text file that can be
easily opened up in Excel.

At wits end...
Sincerely,
Alex
0 Kudos
Message 1 of 5
(2,732 Views)
Hi Alex

Would using a "Build Array" function, with the first terminal as an Array
terminal (the 2D array, wired to the Shift register), and the second
terminal as an Element terminal (1D array), do the job inside your For
loop? This should add a new row to the 2D array for each row of data.

Paul Davey
--

Research Assistant
School of Physiotherapy, Curtin University of Technology
Selby Street, Shenton Park, Western Australia, Australia. 6008
email: P.C.Davey@curtin.edu.au
Tel. +61 8 9266 4657 Fax. +61 8 9266 3699

"Everyone who calls on the name of the Lord will be saved." Romans 10:12
"For all have sinned and fall short of the glory of God, and are justified
freely by his grace through the redemption that came by Christ Jesus."
Romans 3:23-4

Alex Harris wrote:

> Hi all,
>
> I have a problem where I am running a couple of loops that write string
> data into an array but then it writes new data over the last in the same
> array. I don't know how to create new arrays for each row of data
> coming out of the same loop. Below is a description of my program &
> problem.
>
> I have a long string of test data that I have parsed down using "match
> pattern" vi to remove the header info and the column names. For each
> row of data, I need to remove the row names; I have done this with a FOR
> loop/shift register and again used the "match pattern" vi.
> Within the FOR loop:
> To detect the end of the row, I have matched pattern to \r\n and sent
> the "before substring" row of data into a shift register in another FOR
> loop. I then match pattern for three spaces between each piece of data
> and send this data out to an array. Then, the outer loop takes the
> "after substring" data and again parses it to the end of row and sends
> it back into the inner FOR loop that matches patter for the three
> spaces. This continues until all data in string has been handled ( I
> will always have the same number of data to deal with).
>
> The big problem is that I always end up with only the last row of data
> in the array. I know I will need a 2D array but I cannot figure out how
> to do this and index each row into it, given the rest of my program.
> The end goal is to end up with a tab delimited text file that can be
> easily opened up in Excel.
>
> At wits end...
> Sincerely,
> Alex
0 Kudos
Message 2 of 5
(2,732 Views)
Thanks for responding, Paul.
I did finally find a solution which involved some reworking and using a 1D
'Array to spreadsheet String' vi and then 'Write Characters to File' vi. In
this way, I avoided having to create a 2D array. The problem I had with your
suggestion is that I could not figure out how to get a 2D array to begin
with. I right clicked to pop up on the 1D array to add a dimension but then
this would give me a broken wire between the FOR loop and the array. Also, I
couldn't see how the 'Build Array' would work for this because it still looks
like it would write each row of data (the second terminal in the 'Build
Array') over the other 1D array (at the same terminal) as it looped. Maybe I
just don't understand your suggestion or I didn't explain my problem well
enough. Still, you got me thinking about my problem differently.
Thanks,
Alex

Paul Davey wrote:

> Hi Alex
>
> Would using a "Build Array" function, with the first terminal as an Array
> terminal (the 2D array, wired to the Shift register), and the second
> terminal as an Element terminal (1D array), do the job inside your For
> loop? This should add a new row to the 2D array for each row of data.
>
> Paul Davey
> --
>
> Research Assistant
> School of Physiotherapy, Curtin University of Technology
> Selby Street, Shenton Park, Western Australia, Australia. 6008
> email: P.C.Davey@curtin.edu.au
> Tel. +61 8 9266 4657 Fax. +61 8 9266 3699
>
> "Everyone who calls on the name of the Lord will be saved." Romans 10:12
> "For all have sinned and fall short of the glory of God, and are justified
> freely by his grace through the redemption that came by Christ Jesus."
> Romans 3:23-4
>
> Alex Harris wrote:
>
> > Hi all,
> >
> > I have a problem where I am running a couple of loops that write string
> > data into an array but then it writes new data over the last in the same
> > array. I don't know how to create new arrays for each row of data
> > coming out of the same loop. Below is a description of my program &
> > problem.
> >
> > I have a long string of test data that I have parsed down using "match
> > pattern" vi to remove the header info and the column names. For each
> > row of data, I need to remove the row names; I have done this with a FOR
> > loop/shift register and again used the "match pattern" vi.
> > Within the FOR loop:
> > To detect the end of the row, I have matched pattern to \r\n and sent
> > the "before substring" row of data into a shift register in another FOR
> > loop. I then match pattern for three spaces between each piece of data
> > and send this data out to an array. Then, the outer loop takes the
> > "after substring" data and again parses it to the end of row and sends
> > it back into the inner FOR loop that matches patter for the three
> > spaces. This continues until all data in string has been handled ( I
> > will always have the same number of data to deal with).
> >
> > The big problem is that I always end up with only the last row of data
> > in the array. I know I will need a 2D array but I cannot figure out how
> > to do this and index each row into it, given the rest of my program.
> > The end goal is to end up with a tab delimited text file that can be
> > easily opened up in Excel.
> >
> > At wits end...
> > Sincerely,
> > Alex
0 Kudos
Message 4 of 5
(2,732 Views)
Alex Harris wrote in message <397E39E6.E07E4720@ksimaging.com>...
>Hi all,

>I have a long string of test data that I have parsed down using "match
>pattern" vi to remove the header info and the column names. For each
>row of data, I need to remove the row names; I have done this with a FOR
>loop/shift register and again used the "match pattern" vi.
>Within the FOR loop:



Alex

Try passing the string to a "spreadsheet string to array" function. Wire a
string constant of three spaces to the delimiter input. This will produce a
2D array with row breaks at newlines.

Alternatively:

Use "match pattern" within a while loop to replace the three spaces with a
Tab (concatenate a tab to the 'before substring' output, then all of this to
the 'after output'). Use shift registers
for the string, and the index
output to input. Leave the '/r/n's in place. End the loop when the index
output = -1. Save this string to a txt file. You should then be able to open
the file successfully using Excel's import wizard.

Hope this helps

Paul
0 Kudos
Message 3 of 5
(2,732 Views)
Paul F, thanks for responding to my problem.

I ended up using your second suggestion to help me solve my problem. I did have
to make a couple deviations but it sure helped me to take this different
approach than what I had been doing.

Thanks again,
Alex

paul F wrote:

> Alex Harris wrote in message <397E39E6.E07E4720@ksimaging.com>...
> >Hi all,
>
> >I have a long string of test data that I have parsed down using "match
> >pattern" vi to remove the header info and the column names. For each
> >row of data, I need to remove the row names; I have done this with a FOR
> >loop/shift register and again used the "match pattern" vi.
> >Within the FOR loop:
>
> Alex
>
> Try passing the string to a "spreadsheet string to array" function. Wire a
> string constant
of three spaces to the delimiter input. This will produce a
> 2D array with row breaks at newlines.
>
> Alternatively:
>
> Use "match pattern" within a while loop to replace the three spaces with a
> Tab (concatenate a tab to the 'before substring' output, then all of this to
> the 'after output'). Use shift registers for the string, and the index
> output to input. Leave the '/r/n's in place. End the loop when the index
> output = -1. Save this string to a txt file. You should then be able to open
> the file successfully using Excel's import wizard.
>
> Hope this helps
>
> Paul
0 Kudos
Message 5 of 5
(2,732 Views)