05-04-2009 01:41 PM
I am having trouble with a for loop...I am a beginner with Labview and maybe don't follow the order of events (since it doesn't execute line by line like typical programming languages), but I think my problem is trivial.
Say I am running a for loop, for 16 iterations, and I want to build an array that, for example, consists of four 0s, four 1s, four 2s and four 3s. I initialize the array outside, and use shift registers to add to the array in the for loop.
However, the first time I run the program I get funky results. In subsequent runs, the first value in my array is a 3, and the rest of the rest of the array is shifted down by 1, so I only have three 3s at the end (for example).
Can someone help me understand how to solve this problem?
Thanks,
George
Solved! Go to Solution.
05-04-2009 01:53 PM - edited 05-04-2009 01:54 PM
George,
Much easier to build array using FOR loop with auto-indexing.

05-04-2009 02:04 PM
Thanks. The for loop is auto indexed. But I have other variables created in the foor loop and their initial value is triggered by a random numebr generator and based on that, my value say starts either with a 0, 1, 2, or 3, but should never decrease from there.
So, sometimes the second time I run the program, my first value (or soemtimes the first two values) in the array is a 3 (since it was last the last time) and then it starts aggain say with the 0, 1, or 2 value...
05-04-2009 02:17 PM
05-04-2009 02:19 PM
05-04-2009 02:20 PM
george,
I guess I don't understand what you are trying to do. Can you post your code?
05-04-2009 03:00 PM
Sure, i broke out the section that was giving me trouble
Attached is the code.
Basically when healing pattern is 0, then tehe healing31 array should either be all 0s or 1s
When healing pattern is 1, healing31 array should be half 0s then 1s
when healing pattern is 2, the healing31 array should be an even distribution of 0s, 1s, 2s, and 3s
once you run it a second time, the last value for healing 31 starts the new array...it should never start with 2s or 3s
Hope it makes sense
05-04-2009 03:04 PM
The same thing happens with the force array as well.
Actually sometimes the first 2 values in the Healing31 array are the old value...
05-04-2009 03:14 PM
Your code is full of race conditions due to excessive overuse of local variables. There are eight disconnected code fragments in the loop and they can execute in any order becaus there is no data dependecy between them. Your result will vary wildely depeding on the exact execution order. LabVIEW does NOT execute top-to-bottom and left-to-right at all.
Get rid of all the local variables (none are needed!) and wire things together in the order they are supposed to execute.
05-04-2009 03:19 PM