Jump to content

Dinamic Array of 1-D Arrays of Double


Recommended Posts

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? :lightbulb:

Link to comment
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?  :lightbulb:

5244[/snapback]

Use a 1D array of cluster containing a 1D array.

Link to comment

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.

Link to comment
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?  :lightbulb:

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

Link to comment
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! :D

Link to comment
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!

Link to comment
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.

Link to comment
  • 1 year later...

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

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.