LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

passing data through for loop

I am trying to pass data from a text file through a for loop to a chart. The data type is changing when it passes through the for loop. How do I avoid/fix this? I tried to bundle and unbundle the data from the text file and that didn't work.
0 Kudos
Message 1 of 8
(4,087 Views)
If your data is in the form of an array and you pass the array to a for-loop, the default setting is that indexing is enabled (that means that inside your loop you will have the elements, one by one, rather than the array). This means that the data inside the loop is no longer an array. You can disable indexing by right-clicking on top of the point where your array enters the loop. You will then get a pop-up menu with that option.

The same is true for data going out of a loop. The data comes out in the form of an array since indexing is enabled by default.

Hope this helps. /Mikael
Message 2 of 8
(4,087 Views)
When I disable indexing, the data stops passing through the for loop. What can I do?
0 Kudos
Message 4 of 8
(4,087 Views)
I have disabled indexing, and it shows everything is wired correctly. But, the data is only passed through the for loop after N interations. How do I do this in real-time? Out-put one data value for each interation?

Thank you.
Ellie
0 Kudos
Message 5 of 8
(4,087 Views)
Loop-structures are confusing in LabVIEW many times. If you pass data out from a for-loop the data (as an array if you have indexing enabled, or as a single element if you have it disabled) will not be available until the N iterations are completed. Just as you noticed. If you need access to your data every iteration you have move that operation into the loop.

In your application, do you really need to pass it into the loop and then out? What exactly are you trying to do by passing data tru the for-loop? If your data is in the form of an 2D array and you want to plot it on a chart, you can extract the X and Y columnsfrom the array, using the index array function, and then bundle them without even using a for-loop.

If you explain in more
detail what you are trying to do I can attach an example that shows how to do it.

/Mikael
0 Kudos
Message 6 of 8
(4,087 Views)
Could you please provide an example of what you are doing?

Also, if the data in the text file are numbers arranged like a spread sheet, you should be able to read it directly using "read From Spreadsheet File.vi". Check the following example I posted recently which use that vi:

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=5065000000080000008D2A0000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0

(Because it is a long link, if you click at it may not work correctly. Try coping it and pasting in the address field of you browser.)

Hopefully, this can be of help in your situation.

Best regards;
Enrique
www.vartortech.com
0 Kudos
Message 3 of 8
(4,087 Views)
Here is an example that shows how to plot data from a 2D array. Hope this helps. /Mikael
0 Kudos
Message 7 of 8
(4,087 Views)
I just read your other posting about reading data from a file every second. I have noticed that many problems in LabVIEW are related to the difficulty of using shift-registers.

Shift-registers can solve many problems but they are not easy to use the first time. I attached an example that perhaps can be of use for you. It shows a sequential reading from a file (1 reading/s) and a subsequent plot. The plot is updated every second with new data. I have used two shift registers to store the X and Y arrays. To get a shift-register, right-click on the left or right border of a for- or while-loop and select it from the pop-up menu. A shift register gives you data from the left that was at the right at the previous iteration... In oter words, put data to the ri
ght and you can use it in the next iteration. This is useful for adding new elements dynamically to arrays as is shown in my example. In my example I decided to init both arrays as empty arrays before I enter the loop.

I hope this helps.

/Mikael
0 Kudos
Message 8 of 8
(4,087 Views)