09-30-2011 09:13 AM
Hi,
I am trying to have the data from these 5 random inputs being added row by row. I have got it to add the values for the row one at a time, but each time it makes a new row it is deleting the old row. The only reason I used the insert into array function is that when I actually implement the program I wont know how many rows I will have. I have attched the code and a picture of the code is below.
Any help would be greatly appreciated.
Canalian
Solved! Go to Solution.
09-30-2011 09:18 AM - edited 09-30-2011 09:21 AM
You've got to get the result of the append operation back to the next iteration of the loop. You can do this with Shift Registers or, as I've done here, with a Feedback Node. Your code simply appended the new data to the original initialized array each time through.
09-30-2011 09:23 AM
Hi Jim,
Thanks for replying i tried that but I am getting nothing coming out. What have you connected the feedback node to at the bottom?
Thanks again
09-30-2011 09:26 AM
09-30-2011 09:28 AM
@Canalian wrote:
Hi Jim,
Thanks for replying i tried that but I am getting nothing coming out. What have you connected the feedback node to at the bottom?
Thanks again
I took the liberty of simplifying your array initialization.
09-30-2011 09:31 AM
Hi Jim,
That worked great, really apreciate the help
Canalian
09-30-2011 10:52 AM - edited 09-30-2011 10:52 AM
none of the code shown above is a good solution. Because you allocate 100 rows that you never use and just push back with each insertion.
To append rows to the end of a 2D array, use build array. No index needed. No preallocation needed. If you want to append to an existing array, feed it into the shift regsiter on the left before the loop starts.
Of course it is generally much more efficient if you know the number of rows beforehand. In this case you could use a FOR loop and just autoindex at the right loop boundary to form the 2D array. Since this is a finite, tight loop, you don't need any indicators inside.
A long running while loop as in your code needs a small wait, else you quickly run out of memory, forming gigabytes of data structures quickly.
09-30-2011 11:04 AM
I'm guilty of tunnel-vision again. I immediately saw the problem and rushed to provide a solution (twice) without looking at the overall VI. Rats...
09-30-2011 11:14 PM
Hi Altenbach,
I dont understand how you made the shift register on the left hand side. I tried right clicking and adding shift register on loop and the wiring that to the index of the build array but it everything is greyed out, I have inserted a picture so you can see what I mean. Also the symbol for build array looks different than in your diagram have I done somthing wrong there?
Thanks for the help
Canalian
10-01-2011 01:04 AM
pn ur block diagram, use array constant, insert a double numeric constant, at the meeting point of the array and the loop, u can right click and choose replace with shift register.