LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with shuffling and concatenating a 2D array

Solved!
Go to solution

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

0 Kudos
Message 1 of 6
(2,613 Views)

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

0 Kudos
Message 2 of 6
(2,601 Views)

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...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 6
(2,600 Views)

I did attach a VI and used some of your suggestions, with no success. 

0 Kudos
Message 4 of 6
(2,588 Views)
Solution
Accepted by topic author sHrG78

Ok, I did it anyways...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
Message 5 of 6
(2,585 Views)

This is a beautiful and elegant solution.

I wish I had thought about it myself. 

Thank you very much!

I appreciate your help 

 

0 Kudos
Message 6 of 6
(2,577 Views)