10-07-2010 11:47 AM
Hi!
I'm trying to create arrays when I don't know the size prior to creation. For the first step I'm trying to get the current position of a slider and put it to a 1D array. My problem is, that the while loop overwrites the first element of the array instead inserting the new value to the end of the array.
The diagram so far:
Solved! Go to Solution.
10-07-2010 11:54 AM
10-07-2010 11:56 AM
Short answer: Remove the "built array" node and make the inner output tunnel autoindexing. (but keep reading!)
Long answer: Still, this is very bad code, because you will run out of memory in seconds. Either use an inner FOR loop with a limited number of iterations or place a significant wait inside the inner loop. It is typically not a good idea to grow arrays indefinitely. What exactly are you trying to do?
10-07-2010 11:57 AM
Still the first element of the array changes only.
My aim is to get the position of the slider to the array when I press the OK button. Kind of getting a "sample".
10-07-2010 11:59 AM
Actually, looking at your code once more, it seems you want to grow the array inside the outer loop. Place a shift regsiter on the outer loop and use "built array" with the upper connector coming from the left shift register and the lower connector coming from the slide. The output goes into the right shift register. Initialize the shift register with an empty array.
Use an event structure instead of the inner loop.
10-07-2010 12:03 PM
This is a part of a large project the final aim is to log the position of the moving part of an instrument in every x sec. The problem is that the logging will take as much time as necessary for the operator to solve a task, so I cannot say how long the array will be.
I am aware of the possible memory losses, still I don't have a better idea.
Basically I would be content if I could create any of the following:
1: Getting the position of the slider on button press, and writing it to the end of the array.
2: On button press get the position of the slider with a preset sampling frequency and putting it to the array, until the button is pressed again.
10-07-2010 12:31 PM
10-07-2010 12:36 PM
I did. It was an advance, so thank you, but I don't know if I can give any condition to the event structure (it should be active only if I switch the button from OFF to ON), and can I specify some kind of sampling frequency?
Anyway thank you for you help!
10-07-2010 02:02 PM
PierreBatka wrote:1: Getting the position of the slider on button press, and writing it to the end of the array.
2: On button press get the position of the slider with a preset sampling frequency and putting it to the array, until the button is pressed again.
Here's a quick example (LV 8.5) using "elapsed time". Modify as needed.
10-08-2010 02:32 AM
Perfect. Thank you very much, I've learned a bunch of things about LabView.