LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a Dynamic Array

I've been trying to come up with a way to make a dynamic array in LV 6.i so that it's always the exact size to match the data. The way I do it now is to just initialize a huge array like 1000x2 and set everything to zero. Then I use Replace Array to fill in as needed and leave the rest at 0. This works, but takes a long time to execute, isn't guaranteed to be able to manage every data point, and leaves a "ghost plot" at the initial value for the left-over 0's. I'm also not really a pro at using clusters, so if there is a way to do it and keep everything as an array, that'd be ideal. Even better yet, if someone already has a sample .vi made that does this and wants to attach it, by all means...
Thanks
p.s.
Thanks to eve
ryone who answers questions on here and does so, so quickly. You make this site an invaluable resource.
0 Kudos
Message 1 of 3
(2,944 Views)
adam,

I am not sure where you are building the array, but you can use shift registers on a FOR or WHILE loop (use initialize array of whatever type on the outside of loop - wired to shift register on the left side), and then the build array function with two inputs - one wired to the shift register the other to the value you want to add (you may want to right click on the build array and set to concatenate inputs). you can then access the array outside of the loop by wiring to the shift register on the right side. hope this helps

pat
0 Kudos
Message 2 of 3
(2,944 Views)
If you don't want to have left over zeroes in your array, you can dynamically allocate memory each time you receive data. I have attached an example that dynamically creates a 1000x2 array (5x2 at a time), but you can set it up so that it will stop adding to the array when you're done receiving data. Basically, I'm using a shift register (initialized to an empty 2D array) and using a "Build array" function to concatenate my left register with my new data (in the example I have just generated random numbers.)

This is not the most efficient use of memory, but it will eliminate the issue of the ghost plot. Hope this helps!
Message 3 of 3
(2,944 Views)