LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I create sub-arrays based on the positions of indicies in a separate index array?

Solved!
Go to solution

Please forgive me if this question is basic or obvious. I am fairly new to LabVIEW and I'm trying to learn as I go along.

 

I have a 1D array of index values (the number of possible index values is not fixed, but can vary between uses of the application; it could be just {0, 1} on one day and {1, 5, 11, 678} on another) and a 1D array of measurement values (doubles). I'd like to parse the measurement values into sub-arrays for each index, so that if my index array was:

 

[0 1 1 1 1 5 5 0 5 5 1 0 1 1 5]

 

and my measurement array was:

 

[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.10 0.11 0.12 0.13 0.14 0.15]

 

I would get back 3 sub-arrays:

 

[0.1 0.8 0.12]

[0.2 0.3 0.4 0.5 0.11 0.13 0.14]

[0.6 0.7 0.9 0.10 0.15]

 

I know there must be a simple way to do this, I guess I'm just stuck too much in matlab-array thinking to figure it out... please help!

 

-- jph

0 Kudos
Message 1 of 8
(3,168 Views)
Do you want the elements within each group in a specific order?
0 Kudos
Message 2 of 8
(3,163 Views)
Solution
Accepted by topic author jamespherman

One problem is that your subsets are not of equal lenght and you also don't know the number of subsets beforehand, so you need to decide on a suitable output structure. I would suggest an array of clusters, each element containing the subset and possibly the tag.

 

Here's a very quick example (LabVIEW 8.0). See if it makes sense. Please verify correct operation. There could be bugs, but the concept should be clear.

Message 3 of 8
(3,145 Views)

SO GOOD!

 

I really don't know enough about data types in LabVIEW. Thank you so much.

 

However, what I really want to be able to do (should have said this from the beginning, I know) is graph these data points against their trial numbers with different colors for each point (no lines connecting them). I copied your example so that I have trial numbers getting parsed as well, is there an easy way to send the "trial numbers" and "measurements" as X & Y values (respectively) to an XY graph?

 

-- jph

0 Kudos
Message 4 of 8
(3,140 Views)

jamespherman wrote:

...graph these data points against their trial numbers with different colors for each point (no lines connecting them).


Sorry, I don't quite understand. Do you want the same color for each trial number? Every point a different color?

 

(You definitely don't need to duplicate the code. The trial number can be obtained within my code directly.)

0 Kudos
Message 5 of 8
(3,128 Views)

I'M sorry for not being clear.

 

Perhaps I've gone the wrong route with this thing entirely.

 

My goal in general is to make a scatter plot, measurements vs. trial numbers, where the points are colored by the index value. With only two index values, this is easily achieved by sending two sets of XY values to an XY graph, a multi-plot. Thus, I figured it might be possible to generalize this idea and send multiple sets of XY values to an XY graph. Perhaps this is not the best way to go about this. In any case, is that clearer?

0 Kudos
Message 6 of 8
(3,116 Views)

jamespherman wrote:

Thus, I figured it might be possible to generalize this idea and send multiple sets of XY values to an XY graph.


OK, all we need is a trivial modification of what we already have. XY graph data is easiest handled using complex data. Here's a quick rewrite. See if this works for you. 😉

 

 

Message 7 of 8
(3,110 Views)

Wow. Simply Awesome!

 

What I meant, however, was that the "trial number" (the position in the 1D array) would serve as the X-value. It was clearly quite trivial to modify your VI to do that. I can't thank you enough for the help! I am going to learn quite a bit from thoroughly understanding this example.

0 Kudos
Message 8 of 8
(3,105 Views)