Riceman Posted July 8, 2005 Report Share Posted July 8, 2005 My problem is: I have a dynamic number of arrays, each one with different length (size). If I initialize a 2-D Array and then "Insert Into Array" inside a for loop, from the second iteration on all arrays (if greater than the first one) will be truncated to the size of the first array. What I need is a data structure where I can store a dynamic number of variable size arrays. As if each row of a 2-D array had a different number of columns. I've tried using clusters, but the problem is that they can't be of dynamic size. Any Ideas? Quote Link to comment
jpdrolet Posted July 8, 2005 Report Share Posted July 8, 2005 My problem is:I have a dynamic number of arrays, each one with different length (size). If I initialize a 2-D Array and then "Insert Into Array" inside a for loop, from the second iteration on all arrays (if greater than the first one) will be truncated to the size of the first array. What I need is a data structure where I can store a dynamic number of variable size arrays. As if each row of a 2-D array had a different number of columns. I've tried using clusters, but the problem is that they can't be of dynamic size. Any Ideas? 5244[/snapback] Use a 1D array of cluster containing a 1D array. Quote Link to comment
Riceman Posted July 8, 2005 Author Report Share Posted July 8, 2005 Use a 1D array of cluster containing a 1D array. 5247[/snapback] And how exactly do I do that? Quote Link to comment
m3nth Posted July 8, 2005 Report Share Posted July 8, 2005 Big data clusters = Bad news in memory land, but if you're so inclined you can take jpdrolet's suggestion. If you have two For loops... - Outer one goes from 1 to # arrays - Inner one goes from 1 to # array elements for each differently sized array - Index output from inner loop to create a properly sized 1d array - Wire indexed output from the inner loop to cluster Bundle (between inner & outer loop) - Wire output of cluster bundle to outer loop boundary - Index outer loop boundary You now have an array of clusters. Inside each cluster is a properly sized array. Index the array and unbundle to obtain your properly sized array. Usually when I'm doing this kind of thing though it's easiest just to use a 2d array that sized to the max 1d array size, then keep a 1d array of sizes that correspond with each row. Quote Link to comment
Rolf Kalbermatter Posted July 11, 2005 Report Share Posted July 11, 2005 My problem is:I have a dynamic number of arrays, each one with different length (size). If I initialize a 2-D Array and then "Insert Into Array" inside a for loop, from the second iteration on all arrays (if greater than the first one) will be truncated to the size of the first array. What I need is a data structure where I can store a dynamic number of variable size arrays. As if each row of a 2-D array had a different number of columns. I've tried using clusters, but the problem is that they can't be of dynamic size. Any Ideas? 5244[/snapback] The only option would be to create an array of clusters with one array in them. However that is a rather inefficient way for LabVIEW to store data. If your arrays can get large expect a serious slow down of your application. Also wiring such data structures can get rather messy very fast since you need to have all those Index Array, Unbundle, Bundle and Replace Array nodes all over the place. You probably would be best of rethinking your strategy of storing the data if your arrays can get larger than a few 100 elements. Rolf Kalbermatter Quote Link to comment
Riceman Posted July 11, 2005 Author Report Share Posted July 11, 2005 Usually when I'm doing this kind of thing though it's easiest just to use a 2d array that sized to the max 1d array size, then keep a 1d array of sizes that correspond with each row. 5250[/snapback] This last suggestion of yours was the solution I've found before I've got any answer. The thing is that this method includes some case structures and comparisions in the middle of my block diagram that I would like to avoid. Either I have to make 2 FORs (one to find the greatest array, then initialize the 2-D array, and another to add the rows of arrays to it) or 1 FOR (which is the solution I've used) with a case inside checking whether the next array is greater then the dimensions of the 2-D array and if so resize the 2-D array to fit the new one. So, I've waited for suggestions to know whether there was a "cleaner" (without so many cases and comparisions and much less wiring) and more efficient (less time and processing consuming) way to do this. Thanks everyone for your help! Quote Link to comment
m3nth Posted July 11, 2005 Report Share Posted July 11, 2005 Just use the Build Array function in a loop to add rows--the array will automatically resize if an added row has more columns then the previous rows. Quote Link to comment
Riceman Posted July 12, 2005 Author Report Share Posted July 12, 2005 Just use the Build Array function in a loop to add rows--the array will automatically resize if an added row has more columns then the previous rows. 5280[/snapback] Correction to my last post: The method I use did not work because when I resized the array some elements "jumped" to the other rows. I had to use the 2 FORs method to avoid dynamic Array Reshape and initialize with the final size already. I also had problems with the build array, that's why I started using the Insert Into Array VI. Thanks, everyone, again! Quote Link to comment
m3nth Posted July 12, 2005 Report Share Posted July 12, 2005 Correction to my last post:The method I use did not work because when I resized the array some elements "jumped" to the other rows. I had to use the 2 FORs method to avoid dynamic Array Reshape and initialize with the final size already. I also had problems with the build array, that's why I started using the Insert Into Array VI. Thanks, everyone, again! 5285[/snapback] I think you figured this out already (at least it sounds like you did), but Array Reshape is not the same as resizing an array (which there is no single function for--requires an Array Intialize with larger size and then Replace Array Subset). Reshaping an array is equivalent to deleting all the carriage returns in a text file so the text is all on one line, then adding carriage returns at a different place each time to make all the lines 60 characters instead of say, 80--it comes out with all the same data, just in different places (different array dimmensions) than it started out, which is why your elements "jumped" to other rows. What problems exactly did you have using the Build Array function? If you have rows of varying length (ie, varying # elements/columns per row), and you're appending those rows to a 2d array using the Build Array function, the 2d array will always be automatically sized correctly and you shouldn't need to initialize a new array of greater size and fill it. Quote Link to comment
dqsl Posted July 22, 2006 Report Share Posted July 22, 2006 Hi All I've been dealing with the same problem today (which Google-lead me to this site) and I think there's a different approach to the problem: Instead of inserting differently sized 2D arrays into each other, I use the For-loop to make a 3D array of 2D arrays. This doesn't truncate the 2D arrays and the smaller arrays will be patched with zeros to match size the largest. From here there's no problem in unfolding a 3D array (of equal size 2D arrays) to a large 2D array, just initialize a 2D array and use another For-loop to insert the pages one by one, next to each other. I know that this reply comes a year too late Dang Quote Link to comment
crelf Posted July 23, 2006 Report Share Posted July 23, 2006 ...a 3D array of 2D arrays... Great idea dqsl - and welcome to LAVA! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.