Search code examples
arrayslabview

How populate and array whose rows were combinations and columns the different groups?(labview)


I know the question is confusing so I´ll try to explain my problem. I am working in a labview project and one of the things I have to do is, after asking the user the number of variables and number of different values for each one of them, create an array with all de combinations.

Lets supose we have 3 different variables , for example: var1, var2, var3

and the number of diffent values for each of them is:

var1 -> 0, 1, 2
var2 -> 11, 22
var3 -> 55, 66, 77, 88

So, the resulting array should be like this:

0 11 55
0 11 66
0 11 77
0 22 55
0 22 66
...

this way until 3 x 2 x 4 = 24 rows

Taking into account that the number of variables and values of each one usually will be different how can I populate this array?

I need how to do it with labview. Many thanks in advance.


Solution

  • The word you're looking for is "Cartesian Product".

    You can use gmath/Discrete Math.llb/Cartesian Product of Lists.vi to accomplish this:

    labview code

    This gives the intended result:

    result

    The way it works is you feed the Cartesian Product VI a 1D array detailing the size of several arrays you want to get the Cartesian product of, and it generates the corresponding indices you need to index the respective arrays to create the Cartesian product.

    All you need to do is build a 2D array of (1D array of row vectors) that contains all the information you want to compute the Cartesian product of, and a 1D array that shows the size of each individual row vector. In LabVIEW, when you build an array of 1D arrays, the number of columns becomes max(len(row_vector_i)), so to preserve this length information for automatic cross product, the best way is to simply build a 1D array of clusters, where each cluster has an individual 1D array, or row vector. This preserves the size information.

    Here's what that looks like:

    cluster auto

    I saved all of this into a project that should be completely compatible with LV8.6, found here