LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop - How to retain data generated inside even if prematurely termination by user?

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.

0 Kudos
Message 1 of 8
(2,903 Views)
Also append to spreadsheet file is not an option because I can't let my directory get clogged with unneeded data. I mean how I retain the data within labview itself, so that I can offer "save data" command before a loop inside the for loop terminates the program.
0 Kudos
Message 2 of 8
(2,896 Views)

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.

 

0 Kudos
Message 3 of 8
(2,868 Views)
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.
0 Kudos
Message 4 of 8
(2,860 Views)

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.

 

Message Edited by dan_u on 03-05-2010 01:22 AM
0 Kudos
Message 5 of 8
(2,856 Views)

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.

 

Message Edited by Ravens Fan on 03-04-2010 10:04 PM
0 Kudos
Message 6 of 8
(2,832 Views)

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

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 7 of 8
(2,815 Views)

You can do it like this:

 

array inside loop.PNG

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

0 Kudos
Message 8 of 8
(2,812 Views)