LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Collecting an Array data which Reinitializes during each iteration of For Loop

Hi,
 
I am working on a Labview8.5 program, where I am trying to record the magnitude points of a trace shown on the instrument using GPIB-USB cable.
 
Here, I am using a For Loop which contains 2 Sub-VI's, one is for triggering the trace during each iteration and the 2nd is to get an data array of 500 elements.
 
Now the problem is that during each iteration, new array values are observed and the previous values are washedout.
 
So can someone help me out in collecting around 200 array data. I want to record all these data values in a file.
 
Summarizing: a). 1 Array has 500 elements and this is a 1-D array.
                        b). Array values are reinitialized during each For-loop iteration.
                        c). We need to record data from all arrays collectively in a file or matrix whatever.
 
Thanks
0 Kudos
Message 1 of 9
(3,530 Views)
Piscesking,
 
Please post your LV code.  Regards, -SS


0 Kudos
Message 2 of 9
(3,524 Views)

Piscesking,

There are a number of sub-vi's missing?  Can you zip them up and send them all?  Is this a Homework assignment?  🙂

Regards,

-SS



0 Kudos
Message 4 of 9
(3,514 Views)
The subVIs aren't really necessary, as it's clear what the user is trying to do. Currently your VI converts the array of values to a string to display on the front panel. Since you're using a Feedback Node you should be continuously updating the string indicator. Are you trying to display the array of data on the front panel as well? If so, you just need another feedback node wired to a Build Array and to your array of values. The output would be a 2D array, where each column is the data for an iteration.

As for saving it, you can save it after the data collection. If you accumulated the data into a 2D array you can simply use the Write to Spreadsheet File VI  to generate a tab-delimited file. If you want to save it at each iteration then simply place this VI inside the loop.
0 Kudos
Message 5 of 9
(3,507 Views)

Hi,

This suggestion worked, but the concern is the timing gap between each iteration.

A). Does the record time increases when:

  1. We loop back previous values.

  2. When we store in array rather than string.

B). Is there any why so that I can put each iteration data in some buffer (to ensure constant timing interval) and then after completion of for-loop get all values by using either way.

Thanks

0 Kudos
Message 6 of 9
(3,479 Views)
The array accumulation inside the loop will cause memory shuffling as LabVIEW needs to reallocate the array to grow it for each iteration. The same is true with the string. Are you seeing a wide time variation between iterations?

You can minimize this by preallocating a 2D array before the loop since you know how many iterations you're running and how many samples you get for each iteration. Then, inside the loop you would use Replace Array Subset to replace each column with the read data. If you still are doing the concatenation approach for the string you will still have this issue, though you can probably do the same thing for the string.

Another approach is to separate the data collection from the display. In essence you would have a producer-consumer architecture. The producer part would be collecting the data and putting it into, say, a queue. It performs no conversion to string. It's a pure data collection. The consumer part gets the data out of the queue and then converts it to a string for display.
0 Kudos
Message 7 of 9
(3,467 Views)
Hi you wrote: "You can minimize this by preallocating a 2D array before the loop.Then, inside the loop you would use Replace Array Subset to replace each column with the read data."
 
Well as I am new to labview, so can you tell me how to do preallocation before the loop and then to replace each column with read data inside the loop. If you have some VI for that, then that will be great.
 
Showing data is not a concern to me, I want the data out in any file regardless of approch. So if I can get some VI for producer-consumer architecture then that will be fine too. Only concern is to get the data values out using the least time. Well instrument has capability to sweep the trace in 5msec.
 
Thanks
0 Kudos
Message 8 of 9
(3,413 Views)
Here is a simple example of pre-allocating the array and then using Replace Array Subset:



You can take a look at the KB article "Application Design Patterns: Producer/Consumer" for an overview of that architecture.


Message Edited by smercurio_fc on 05-27-2008 11:45 AM
0 Kudos
Message 9 of 9
(3,408 Views)