LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

looping arrays

I have a while loop which is generating data with each iteration, and i want to store each element of data in an array, which will contain all data from the previous iteration, and I want to have access to this array from inside the loop as it is created. If I use build array it simply creates a new array with each iteration of the loop, and if i create the new array outside of the loop, it just pulls the original array back in when I add to the array from inside the loop. I am using lab view 6i. Thanks.
0 Kudos
Message 1 of 10
(3,269 Views)
I would create the array outside the loop and then feed it through a shift register into the loop. The shift register will carry variables (in this case an array) from iteration to iteration. Inside the loop, I would add to the array using build array (right click on build array and choose Concatenate Inputs). I think that this would be the easiest way to accomplish this.

Rob
0 Kudos
Message 2 of 10
(3,269 Views)
Is there any way of knowing ahead of time how many element will be in the array? The problem with the build array is that if the loop will be iterating many times it gets very inefficient because LabVIEW is having to constantly reallocate memory.

If you can calculate how many values will be in the output array (or if there is a theoretical maximum size for the data) a more efficient way of building this array is to create an array of the proper size to initialize the shift register Rob discussed and use the replace array element function to update the values. Updating an element in an existing array is much faster than building the array one element at a time.

The only complication to this technique is if you can't know at runtime exactly how many elements
the array needs and instead initialized the array with the theoretical maximum array size mentioned above. In this case, you might need to have a second register that maintains a count of the number of elements that were actually used, then when the loop terminates the value left in this shift register is used to split the data array to remove the unused elements.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 10
(3,269 Views)
I did not use build array, I instantiated the array outside of the loop, and then I used the while loop's counter to use "insert into array" in order to create the array, because this will automatically resize the array as needed. Is this still inefficient, or does labview have some sort of memory management going on behind the scenes when I use this. Theoretically I could calculate a maximum size, but it would have to be based upon the response time of a piece of hadware that I have yet to receive.
0 Kudos
Message 4 of 10
(3,269 Views)
The problem with "insert into array" is that it inserts a new element at the location specified--which is as bad as the build array function. Updating elements (using the loop counter as the index) is really the way to go.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 10
(3,269 Views)

How do you create an array outside the loop then using Shift reg feed it back into the loop.  I tried and I keep getting broken lines.  Isn't that like recursive?  Your feeding the info from the array back into itself.

0 Kudos
Message 6 of 10
(2,705 Views)

Hi Mark,

 

that's not recursion - it's dataflow Smiley Wink

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 10
(2,695 Views)

You added to a discussion that is 9 years old. Maybe you should hyave started a new question instead.

 


@MarkDavid wrote:

How do you create an array outside the loop then using Shift reg feed it back into the loop.  I tried and I keep getting broken lines.  Isn't that like recursive?  Your feeding the info from the array back into itself.


Your description makes no sense. Please attach your code or at least show us a picture of it.

 

(What kind of loop? What are "lines", "wires" perhaps?  feed back from where to where?)

0 Kudos
Message 8 of 10
(2,693 Views)

@altenbach wrote:

You added to a discussion that is 9 years old. Maybe you should hyave started a new question instead.

 



At least he tried searching the forums for an answer. I agree he should have started a new thread once he didn't find what he was looking for but I do give him credit for trying to at least search for an answer.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 10
(2,683 Views)

Yeah, thanks for the help and support.  The question asked was almost exactly the same one I had so I thought I'd give it a shot.

0 Kudos
Message 10 of 10
(2,664 Views)