LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

collecting data from nested loops

I have ended up with a program having "case" loop at the top level and 3-4 nested "for" and "while" loops. Now from the inner most loop from each "case", I want to pull out the data, fromat it and then write it in a excel sheet. The problem is that I am not able to pull out the data. Everytime I try to do it, the dimension of array changes due to the nested loops. Is there a better way to do it?
 
Thanks,
Vivek
0 Kudos
Message 1 of 10
(2,806 Views)
You can do it as you describe. You just have to right klick on the node on the right side of the loop and make sure that "Enable indexing" is not checked.
 
Hope this helps.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 2 of 10
(2,798 Views)
Ohh Thanks!! Smiley Happy
0 Kudos
Message 3 of 10
(2,796 Views)

There is no single right answer to your question, because we don't know what kind of data you want in your spreadsheet.

If you disable indexing as suggested above. you'll only get data out once all loops have finished, and you only get the last bit of data generated during the last iteration of each loop.

If you want to append all data to your file as it is generated in the innermost loop, you would need to place your file write operation right there inside all the loops.

If you like, please attach your code and we can figure out the best solution. 🙂

0 Kudos
Message 4 of 10
(2,782 Views)
As altenbach said, it'd be best to see your code, but as you mentioned that formatting needed to be done before writing it to a file, why not leave indexing enabled, then rearrange the arrays?

You can get all the dimensions by passing the "i" out of each loop (not indexed), and that number will be the size of that dimension, then you can just use the array functions to format the data to any configuration you wish!
0 Kudos
Message 5 of 10
(2,773 Views)
I ma attaching the snapshot of my block diagram. I want to collect the power and current values that are getting generated in the innermost loop. I will have to do some kind of formatting before writing to excel sheet.
0 Kudos
Message 6 of 10
(2,761 Views)

(Please don't attach any 4MB bmp files! even MSpaint can save it as gif or png which would cut the size down to a few hundred kb or less. Not everybody has a highspeed internet connection!)

The innermost loop is a while loop and from what I can tell, it does not generate any data. Thus I am assuming the inner FOR loop.

Easiest would probably be to initialize an empty array on the left and feed it via shift registers across all the FOR loops. In the inner FOR loop, use built array to append the data as you go. At the end, write to file.

Just to clarify, do you want to (1) write your data to a plain spreadheet file of do you want to (2) write in in the proprietary Microsoft excel format? Case (2) is a bit more complex.

Message Edited by altenbach on 07-15-2005 02:52 PM

0 Kudos
Message 7 of 10
(2,747 Views)

I further need help for writing data to the excel sheet. I am planning to run three different "casees" and then collect all of the data from 3 cases and store them finally in a excel sheet. But what is happening is that as soon as the case changes the program loses the data from old cases and  the data only from last case is been written to the excel.

The possible solution is to drag the "file writing" code with the case loop. But the thing is, I am not able to write data to same excel sheet. I am using the VIs that are available in report generation slot.

Any solutions? I am attahcing the snapshot for clarification..
0 Kudos
Message 8 of 10
(2,722 Views)
The reason you're only getting the last "case" is because you haven't got the for loop indexing your data.  If a loop tunnel is not indexed, but data is being passed to it in more than one interation, only the data passed to it in the last iteration is available outside the loop, as all data passed to it in previous iterations has been overwritten.

Try indexing the loops, then manipulating the arrays you get out of it (as they will be a dimension larger than they already are) to fit what they used to be.  I have used "reshape array" many times for this same purpose.

hope this helps.
0 Kudos
Message 9 of 10
(2,718 Views)
It is not possible for us to troubleshoot the code from an image that only show part of it.
From what I can see, a lot of things don't make much sense. Also please don't run wires backwards (such as the wires from the "How many channels" Control entering the big loop from the right.) This can make reading and debugging a diagram very difficult!
 
Let's look at the inner FOR loop on the right: It runs several times, generating 1D arrays each time.
Leaving this loop, they autoindex into 2d arrays, whitch you reshape into 1D arrays.
Leaving the next loop some are autoindexed into another 2D array, except for the top one, where you only retain the data from the last iteration. Is that really what you want?
Now we exit a case strucure, where apparently each case has it's own three outputs, so for each case, One set contains data, but the other two sets generate empty data. About 2/3 of all your data is zero, this is a lot of wasted memory!
Leaving the big FOR loop, nothing is indexed, meaning you only get sets of 1D and 2D arrays from the last iteration. If you would autoindex, you would get 2D and 3D arrays.
 
As you can see, this all make little sense unless we can see the code and some real data. Also, you have not implemented any of my suggestions from above. Why not?

Message Edited by altenbach on 07-21-2005 08:37 AM

Message 10 of 10
(2,707 Views)