LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

creating a new 2D array with two 2D arrays

I have two 2D arrays. I want to create a new 2D array whose zeroth colums will be the zeroth columnn of the first 2D array, first column will be the zeroth column of the second 2D array, second column will be the first column of the first 2D array, thirth column will be the first column of the second 2d array and so on. So bascially the second 2d array is inserted in to the first one like a comb and a new 2d array having doubled number of columns is created.

Does anybody have a VI which can perform this task, which may be called 'combing' two 2D arrays.

Thanks
0 Kudos
Message 1 of 9
(4,196 Views)
If I understand you correctly, you can do this with an Index array and a couple Insert Into Array functions. See the attached picture.
0 Kudos
Message 2 of 9
(4,196 Views)
It looks like it works only if both 2D arrays has 2 columns max. But I guess it may be modified with a for loop which returns proper insert values to the 'insert array' when the 2d array has more number columns (more than 2).
My 2 d arrays (both) have number of columns more than 2 for sure.

Thanks for your help
0 Kudos
Message 3 of 9
(4,196 Views)
Indeed, your vi will not work for any 2D array but only 2-column 2D arrays. The question is how to do it efficiently, so that the Vi can 'comb' any inout 2D arrays, not arrays with a certain number of column.
FYI, you understood well what I am trying to do, except the column number of the 2D array. I didn't mean 2-column 2D array but any 2D array with unspecified number of columns.
I hope I explained it better.
0 Kudos
Message 4 of 9
(4,196 Views)
"akcay" wrote:
> I have two 2D arrays. I want to create a new 2D array whose zeroth
> colums will be the zeroth columnn of the first 2D array, first column
> will be the zeroth column of the second 2D array, second column will
> be the first column of the first 2D array, thirth column will be the
> first column of the second 2d array and so on. So bascially the second
> 2d array is inserted in to the first one like a comb and a new 2d
> array having doubled number of columns is created.

Assuming that the two 2D arrays are of the same size (same number of rows and
columns), you could do the following:

1. Transpose each array with the Transpose 2D Array function.
2. Wire both arrays auto-indexed into a For Loop.
3. Put a shift register onto th
e For Loop. Initialize the shift register with
an empty 2D array.
4. Run the left shift register terminal into a Build Array function, then the
output of the Build Array to the right shift register terminal.
5. Wire each input array auto-indexed row into the next two inputs of the
Build Array function.
6. Transpose the 2D array coming out of the For Loop at the right shift
register terminal. This transposed array is your desired result.

That's probably the most compact solution. It may or may not be the most
efficient.

Joe Czapski
Electronics Engineer
AutoMeasure
Boston, Mass.
0 Kudos
Message 5 of 9
(4,196 Views)
Thanks,

I'll try what you wrote. By the way, your assumption is correct, that is both 2D arrays have the same size.

ceyhun
0 Kudos
Message 6 of 9
(4,196 Views)
I just tested this and it does what you want - it may or may not be the most time-efficient way:

ASSUMING ARRAY "A" and ARRAY "B" ARE THE SAME SIZE:

Use ARRAY SIZE on array A
Use ARRAY INDEX to get # columns (index #1) from the ARRAY SIZE output

Wire # Columns to N input of FOR loop
In FOR loop, put two INDEX ARRAY functions.
Wire array A thru loop to array input of INDEX ARRAY #1. DISABLE INDEX at tunnel.
Wire array B thru loop to array input of INDEX ARRAY #2. DISABLE INDEX at tunnel.

Wire I (loop counter) to INDEX #1 (the second one) of both INDEX ARRAY functions.

The output of these is the current column of each array

Use BUILD ARRAY with three inputs:
Input 1 is from left SHIFT REG.
Input 2 is output of top Column-selector (
Index Array)
Input 3 is output of bottom Column-selector (Index Array)
Output is to right SHIFT REG.

Init the SHIFT REG with an empty 2-D array.

Transpose the output SHIFT reg and there's your result.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 9
(4,196 Views)
Thanks for your answer. It works as exactly I want!
But, let me complete your answer by adding one more stage. At the end I had to use ARRAY SUBSET to get rid of the 2D array used as input to the left SHIFT REGISTER because it appears in the first columns of the final 2D array. The number of columns of the init 2D array should be wired to INDEX #1 of the ARRAY SUBSET.

Thank you again. Very good answer.
0 Kudos
Message 8 of 9
(4,196 Views)
see attached VI for a solution using the built in 'Interleave 1D array'
function


-Franz


"akcay" schrieb im Newsbeitrag
news:50650000000800000055910000-1042324653000@exchange.ni.com...
> I have two 2D arrays. I want to create a new 2D array whose zeroth
> colums will be the zeroth columnn of the first 2D array, first column
> will be the zeroth column of the second 2D array, second column will
> be the first column of the first 2D array, thirth column will be the
> first column of the second 2d array and so on. So bascially the second
> 2d array is inserted in to the first one like a comb and a new 2d
> array having doubled number of columns is created.
>
> Does anybody have a VI which can perform this task, which may be
> called 'combing' tw
o 2D arrays.
>
> Thanks



[Attachment Untitled.vi, see below]
Message 9 of 9
(4,196 Views)