07-19-2013 01:37 PM - edited 07-19-2013 01:43 PM
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]
Solved! Go to Solution.
07-19-2013 01:42 PM - edited 07-19-2013 01:46 PM
Only real solution is an array of clusters each containing another array.
07-19-2013 01:43 PM
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.
07-19-2013 01:45 PM
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?
07-19-2013 01:45 PM - edited 07-19-2013 01:47 PM
Some quick ideas:
07-19-2013 01:49 PM
@Don_Phillips wrote:
Only real solution is an array of clusters each containing another array.
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.
07-19-2013 02:04 PM - edited 07-19-2013 02:12 PM
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.
07-19-2013 02:06 PM - edited 07-19-2013 02:06 PM
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.
07-19-2013 02:19 PM
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…
07-19-2013 02:23 PM
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?