07-22-2011 02:51 PM - edited 07-22-2011 02:53 PM
Hey Guys, I'm trying to dynamically add to a 2-D array. This array will eventually be nx6. We'll suppose it's a 3x2 for now. How do I go about doing this? 1) initialize a 3x2 array of 0's outside the while loop 2) Add a 1x2 array to this array as the 'next row' How do I convert 2 doubles into a 1x2 array? The build array only concatenates the doubles into a 2x1 array. Would I use insert into array? This function only takes in 1 number in the index input. Can I reference using [i,j]? After I add the 1x2 array, I want to use the shift register to keep growing the array. Any thoughts?
Solved! Go to Solution.
07-22-2011 03:21 PM
Rather than Insert Into Array, use Replace Array Subset with an array initialized outside the loop to the maximum size you will need. This avoids frequent memory reallocations which hurt performance and eventually will crash the program.
Lynn
07-22-2011 04:06 PM - edited 07-22-2011 04:08 PM
You will need to remove the extra element on the Index Array function for this to work.
Edit: This statement was in error, but I posted before I caught it.
07-22-2011 04:17 PM
I want to record data for an extended period of time, so I will use a while loop. How would I incorporate a while loop into your code?
07-22-2011 04:40 PM
Try this. You can adjust the timer setting while the measurements are taking place. The array size that it's initialized to is irrelevent because it will continue to append to the array until the timer expires.
07-22-2011 04:43 PM
Sorry, the stop button was behind the time delay.
07-22-2011 05:53 PM
When I change it to a while loop, the output doesn't register (the data only seems to exist inside the while loop and is wiped as soon it exits the while loop).
However, in the for loops, the data exists outside the for loop. Does anybody know why it happens this way? If I want to use a while loop, would I have to create a reference to a data field within the while loop?
07-22-2011 05:56 PM
@MoReese:
Could you post a screenshot of the VI, or vi compatible with labview 7? (yes i'm behind on the times)
07-22-2011 06:28 PM
Here you go. Change the tunnel on the while loop to a shift register. This will accumulate the data from one iteration to the next. This is similar to the .jpg for loop in your post. I'm not sure, but your output shift register on the for loop doesn't appear to be wired to the Insert to Array function output.
07-22-2011 07:01 PM
So for loop and timed while loop work, do you know why a normal while loop won't work?