LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert into array keeping previous values

Solved!
Go to solution

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

 

Untitled.png

0 Kudos
Message 1 of 20
(17,095 Views)

feedback.png 

 

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.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 2 of 20
(17,090 Views)

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

 

0 Kudos
Message 3 of 20
(17,084 Views)

By the way...

 

btw.png works, too.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 4 of 20
(17,080 Views)

@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

 



clear.png

 

I took the liberty of simplifying your array initialization.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 5 of 20
(17,076 Views)

Hi Jim,

 

That worked great, really apreciate the help

 

Canalian

0 Kudos
Message 6 of 20
(17,072 Views)

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.

Message 7 of 20
(17,061 Views)

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...

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 8 of 20
(17,056 Views)

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

 

2.png

0 Kudos
Message 9 of 20
(17,026 Views)
Solution
Accepted by topic author Canalian

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.

Message 10 of 20
(17,019 Views)