08-02-2018 11:28 AM
I have a 2D array and each column in it contains different parameters to run a test with. For example, column A is different values of voltage and column B is different values of input noise.
I need to create a 2D array that contains rows of all the possible combinations.
Attached is a VI with my attempts to solve this task. This VI has a simple 2D array for testing the algorithm but practically I will have unknown numbers to columns and an unknown number of parameters.
I managed to get something but it's not good enough because the output is not containing all the combinations.
I'm not a student and this is not homework.
Thanks
Solved! Go to Solution.
08-02-2018 12:05 PM
I'm going to assume that the A and B arrays have no duplicates (i.e. A = 1, 2, 3, 4 is OK, A = 1, 2, 2, 4 is not). So for every (unique) element of A, you want to pair it with a (unique) element of B.
By now, you should know about For Loops and what happens when you bring a 1D Array (represented by a thick wire) into and out of a For Loop -- the default Tunnel is an "Indexing Tunnel" (if you look closely, you'll see the little symbol [], back-to-back brackets symbolizing an Array) that turns an Array in to an indexed element of the Array (so that the Loop will pick off the elements of the Array as it runs, and will exit when all have been processed), and builds up the Array from elements on the output side.
So bring A into a For Loop. Each time through the loop, you'll get a new element of A. Now you have to pair it with all of the (unique) elements of B. Bring B into the For Loop. Oops, it also came in on an Array tunnel, but you want the whole array. No problem, right-click the Indexing Terminal and in the Drop Down, disable Indexing. Now you have an Element of A and the entire B array, and want to pair the A element with each of the elements of B. By now, you should recognize that "each of the elements of B" means that you bring B into a For loop to "peel of" each of its elements. So put a second For loop inside the first one, bring the A element and B array in (you'll have an ordinary and an indexing tunnel), and now inside the loop you have A and B elements. You want to make them into a 1D array (a "row"), which you do by wiring them to "Build Array". Now you have one row. Bring it out of the inner For Loop. Oops, another Indexing Tunnel, trying to make this a 2D array, but we're not ready for that yet, so again, right-click the output tunnel and make it non-indexing. Finally, bring out the row array having a unique A and B pair, let it index, and presto, a 2D array of unique A, B pairs (each row being a unique pair).
Why did I not attach a VI? I'm attempting to teach, and get you to build the VI. Enjoy.
Bob Schor
08-02-2018 12:08 PM
I think you are going to want to use a recursive VI to accomplish this goal. To start, open the VI properties and go to the Execution tab and choose "Shared clone reentrant execution". Now you can have your VI call itself! So what you can do with this now is have each layer remove a column and build up all of the combinations for that row. Keeps recursing until you reach the last column.
I really wish I had time to code this up. Maybe later tonight...
08-02-2018 12:25 PM
I did attach a VI and used some of your suggestions, with no success.
08-02-2018 12:30 PM - edited 08-02-2018 12:31 PM
Ok, I did it anyways...
08-02-2018 01:17 PM
This is a beautiful and elegant solution.
I wish I had thought about it myself.
Thank you very much!
I appreciate your help