LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Uneven 2-D Array

Solved!
Go to solution

I would like to start off by stating that I KNOW that 2-D arrays have n by m dimensions.  What I need is illustrated below.  Does anyone know a simple way of implementing this?  I cannot think of an elegant solution:

 

Original Array

[a]  [b]  [c]  [d]  [e]

[f]  [g]  [h]  [i]  [j]

[k]  [l]  [m]  [n]  [o]

[p]  [q]  [r]  [s]  [t]

 

 

Then remove an element [n].  (element array[2][3])

 

 

[a]  [b]  [c]  [d]  [e]

[f]  [g]  [h]  [i]  [j]

[k]  [l]  [m]  [o]  XXX  <--  Notice that [o] moved over, and this row now only holds 4 elements

[p]  [q]  [r]  [s]  [t]

 

Then remove an element [k].  (element array[2][0])

 

[a]  [b]  [c]  [d]  [e]

[f]  [g]  [h]  [i]  [j]

[l]  [m]  [o]  XXX  XXX  <--  Notice that [l][m][o] all moved over, and this row now only holds 3 elements

[p]  [q]  [r]  [s]  [t]

 

Etc...

 

Is this feasible?  And if so, what do you recommend as an approach? 

 

Ideally I would like to be able to add and remove from the arrays and if a row is completely removed, then the row is completely removed.  I.E.  There would only be 3 rows (index [0-2]) if I also removed [l], [m], and [o]. 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

 

Edit: 

 

Does LabVIEW have a linked-list style data stucture?

 

After more brainstorming I think something like this would work in C:

 

Original Linked-List of Linked-Lists  (2-D array implemented via Linked stuctures)

 

[a]->[b]->[c]->[d]->[e]

 ↓

[f]->[g]->[h]->[i]->[j]

 ↓

[k]->[l]->[m]->[n]->[o]

 ↓

[p]->[q]->[r]->[s]->[t]

 

Remove element [o].

 

[a]->[b]->[c]->[d]->[e]

 ↓

[f]->[g]->[h]->[i]->[j]

 ↓

[k]->[l]->[m]->[n]-XXX

 ↓

[p]->[q]->[r]->[s]->[t]

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 1 of 19
(3,069 Views)

Only real solution is an array of clusters each containing another array.

 

2013-07-19 13_46_03-Untitled 1 Front Panel _.png

Message 2 of 19
(3,058 Views)

You cannot do that with 2-D arrays.  They must be rectangular, no missing elements among rows or columns.

 

You could create a 1-D array of a cluster of 1-D arrays.  Each cluster could represent a row of your current 2-D array.  Because it is a cluster, the array element inside of that cluster element can be of different lengths.  If you want to remove an entire row, then you could remove that element out of the uppermost 1-D array.

Message 3 of 19
(3,055 Views)

For a cluster approach, would it just be like this?

 

Array of clusters -> Cluster1[holds array1], Cluster2[holds array2], Cluster[holds array3]

 

And how would I implement this in LabVIEW?  I rarely use clusters.  I know how to bundle an array, but do i just Build Cluster much like I use the Build Array function?

 

 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 4 of 19
(3,052 Views)

Some quick ideas:

  • I'm not sure what kind of data you'll have (integers, strings, etc.), but instead of "deleting" the entry, set it to NaN (not a number). You could have a check that when a row is all NaN, delete the row.
  • With the "linked list" idea, have a cluster of 1-D arrays instead of a 2-D array. You'd have to decide to split it up by column or by row, but it could be done. With the cluster, it wouldn't matter if the 1-D arrays were different sizes.
Message 5 of 19
(3,051 Views)

@Don_Phillips wrote:

Only real solution is an array of clusters each containing another array.

 

2013-07-19 13_46_03-Untitled 1 Front Panel _.png


 

 Could you show the code you used bundle the arrays like that?  It looks identically to what I am imagining.  I just struggle with clusters and bundling 😛  It just confuses me, so I avoid them like the plauge.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 6 of 19
(3,045 Views)

http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Add-Support-for-Array-of-Array/idi-p/1875123

 

Looks like others have run into this issue… But until it's supported, just use an array of clusters of arrays.

 

Follow-up Question: Why use an array of clusters where each cluster has only one array? Couldn't you use a cluster of arrays? From a simple VI that I made to test, the output looks the same. I'm guessing it's due to indexing issues (maybe?) but I really wouldn't know.

0 Kudos
Message 7 of 19
(3,017 Views)

Would you mind posting some code as to your idea?  I dont understand the difference between the two solutions that you are suggesting.

 

Also, will your approach be index'able?  That is something I will be needing.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 8 of 19
(3,014 Views)

They both can handle uneven array lengths.

 

What I originally suggested was Cluster(Array1, Array2, etc.), but what NI and the other users suggested was Array[Cluster(Array1), Cluster(Array2), etc.]

 

From what I can tell, there's no advantage of using an Array of Clusters of Arrays…

Download All
Message 9 of 19
(2,998 Views)

I understand the difference now, but I think I favor their approach.

 

If you have an array of clusters of arrays, you can reference each cluster by index as well.  (To remove a whole row for example).

 

I don't believe there is any way to unbundle by index, is there?  For example, remove array #2 from a cluster of 5 arrays?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 10 of 19
(2,995 Views)