03-04-2010 05:21 PM
I have a loop that executes x times and each time generates a unique data point. If I wanted to give the user the ability to stop the loop before it finishes, an eventually save the data, how can I keep a hold of the data that has been generated up to that point? If I put an array outside of a loop the data doesn't get filled in until after the loop is complete, and an array inside of the loop only retains one data point for some reason.
Please keep in mind that I am relatively new to LabView so would appreciate fully explained answers.
03-04-2010 05:25 PM
03-04-2010 06:05 PM
You can use auto-indexing. For a for loop this is default, for a while loop you have to right-click the tunnel and change it to auto-indexing.
03-04-2010 06:15 PM
03-04-2010 06:21 PM - edited 03-04-2010 06:22 PM
Then you will need a shift register (SR).
There's 2 options:
1) initialize the SR with an empty array and use the build array function in each iteration. This is not efficient in terms of memory handling and performance, but simple to implement.
2) initialize the SR with an array of the maximum length you expect and replace an element in each iteration.
When doing operations in the loop option 1 is simpler to handle.
03-04-2010 09:03 PM - edited 03-04-2010 09:04 PM
BobJohnsonNI wrote:
However the auto-indexing doesn't seem to actually output the data for use until all the loop iterations are complete. In my case though I may need to do stuff with the data that has already been generated before it completes.
How do you figure that? The auto-indexing tunnel will return values for all the iterations that have been completed. Post your VI if you are still having problems.
03-04-2010 11:51 PM
Hi Bob,
I haven't seen you vi yet, but let me take a wild guess. With the auto-indexing, are you trying to access your array inside the loop? There will be no array inside the loop, since the loop is indexing (one element at a time). If you want an array inside the loop, you really need to take the shift register - build array approach.
Yik
03-04-2010 11:56 PM
You can do it like this:
You don't have to use "build array". You can pre-allocate the array and use "Replace Array Subset". It's a lot more efficient from a memory standpoint, assuming you know what the maximum size of your array will be (as seems to be implied from your first post).
It is what dan_u was suggesting in the second point of his second post. This is just a picture of what he already suggested, so if this solves your problem, please mark his post as the solution.
d