LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to build a cluster array dynamically from another cluster array?

I'm working on a problem where I seem to be getting lost in a sea of
possibilities, none of which strikes me as optimum. Here's what I need to do.

I've got an input array of clusters (ARR1). Each cluster contains the
following components: an integer (INT1), a ring variable (RING1), a boolean
(BOOL1) and a cluster which itself is simply a bunch of ring variables
(CLUST1) Now, I need to transform that into a set of clusters (CLUST3) each of
which contains an array of characters (CHARARY2), a copy of the ring variable
(RING2), a copy of the boolean variable (BOOL2) and a copy of the cluster
(CLUST2).

To build the CLUST3, I need to find all elements within ARR1 that have the
same unique combination of RING1 and BOOL1, and if BOOL1 is True, then RING1
in addition, build an array of all the INT1 values corresponding to each
unique combination above converted to character, and then bundle this array
plus the unique combination of the other variables into a new cluster. In
general I could have several such clusters.

So if I had the following array to start with:

Index INT1 RING1 BOOL1 CLUST1
---------------------------------------------------
0 3 1 F {Values1}
1 2 1 T {Values2}
2 4 0 F {Values1}
3 6 0 F {Values3}
4 1 2 T {Values2}
5 4 2 T {Values2}
6 3 0 T {Values3}
7 4 2 T {Values3}

I should end up with the following clusters:

CHARARY2 RING2 BOOL1 CLUST1
-----------------------------------------------------
"3" 1 F Don't care
"2" 1 T {Values2}
"4","6" 0 F Don't care
"1","4" 2 T {Values2}
"3" 0 T {Values3}
"4" 2 T {Values3}

What methods would you suggest for accomplishing this easily and efficiently?

Alex Rast
arast@inficom.com
arast@qwest.net
0 Kudos
Message 1 of 2
(2,806 Views)
Tedious but not conceptually difficult.

ARR1 goes into a for loop, auto indexed on the FOR loop. The for loop has a
shift register which will be used to build the output array. Nested within
the for loop is another for loop, which the shift register array goes into,
again auto indexed, along with the element that has been auto-indexed from
ARR1. This for loop has a shift register, initialised with a boolean "true".
The inner loop compares the current element of ARR1 with the output array
and if an element in the output array is already present which matches the
input by your criteria, then the boolean register is set false; otherwise it
is left alone.

After the nested FOR loop you have a case fed from the boolean shift
register; if the boolean is true, the new element is unique and should be
added to the array. If it is false then a previous element has been found
making the present one redundant, and the array should be passed through
without adding the element.

In the true case, you simply unbundle the original element into its
components and build the new element, using "build array".

Notes for if the above is easy for you;

1) if handling lots of data then pre-initialise the shift register of your
outer loop with the same number of elements as your input array. Use
"Replace Array Subset" instead of "Build Array" to insert the current
element into the pre-allocated memory rather than having to create a new
array and copy all the current data across, which is what "Build Array" is
doing. Use "Array Subset" at the end to obtain a new array containing just
the elements you've used, removing the unused ones at the end.

2) Again for large datasets- the use of a while loop instead of the inner
for loop is more efficient since you can halt the while loop as soon as a
duplicate is found. With the described approach you have to go through the
whole array even if the first element turns out to be a duplicate- much
wasted computer time.


Alex Rast wrote in message
news:4Dqs7.843$bL5.373760@news.uswest.net...
> I'm working on a problem where I seem to be getting lost in a sea of
> possibilities, none of which strikes me as optimum. Here's what I need to
do.
>
> I've got an input array of clusters (ARR1). Each cluster contains the
> following components: an integer (INT1), a ring variable (RING1), a
boolean
> (BOOL1) and a cluster which itself is simply a bunch of ring variables
> (CLUST1) Now, I need to transform that into a set of clusters (CLUST3)
each of
> which contains an array of characters (CHARARY2), a copy of the ring
variable
> (RING2), a copy of the boolean variable (BOOL2) and a copy of the cluster
> (CLUST2).
>
> To build the CLUST3, I need to find all elements within ARR1 that have the
> same unique combination of RING1 and BOOL1, and if BOOL1 is True, then
RING1
> in addition, build an array of all the INT1 values corresponding to each
> unique combination above converted to character, and then bundle this
array
> plus the unique combination of the other variables into a new cluster. In
> general I could have several such clusters.
>
> So if I had the following array to start with:
>
> Index INT1 RING1 BOOL1 CLUST1
> ---------------------------------------------------
> 0 3 1 F {Values1}
> 1 2 1 T {Values2}
> 2 4 0 F {Values1}
> 3 6 0 F {Values3}
> 4 1 2 T {Values2}
> 5 4 2 T {Values2}
> 6 3 0 T {Values3}
> 7 4 2 T {Values3}
>
> I should end up with the following clusters:
>
> CHARARY2 RING2 BOOL1 CLUST1
> -----------------------------------------------------
> "3" 1 F Don't care
> "2" 1 T {Values2}
> "4","6" 0 F Don't care
> "1","4" 2 T {Values2}
> "3" 0 T {Values3}
> "4" 2 T {Values3}
>
> What methods would you suggest for accomplishing this easily and
efficiently?
>
> Alex Rast
> arast@inficom.com
> arast@qwest.net
0 Kudos
Message 2 of 2
(2,806 Views)