Concatenate Multiple Arrays in LabVIEW

Updated Aug 28, 2023

Reported In

Software

  • LabVIEW NXG
  • LabVIEW

Issue Details

I have multiple different arrays that I need to combine or concatenate in LabVIEW. Some of the arrays have different dimensions. How do I adjust an array size and concatenate arrays together?

Solution

You can concatenate multiple arrays by using the Build Array function. This function works in two modes: either appending elements to an n-dimensional array, which is the default mode, or concatenating multiple arrays.

The Build Array function will work in concatenate mode when Concatenate Inputs has been selected from the shortcut menu. You can access the shortcut menu by right clicking on the VI.
 


 

The following code segment demonstrates the difference between the output from the build array function before and after you switch it to Concatenate Inputs. The first image below shows the code, the second shows the corresponding result on the front panel. You can see that the output of Build Array with Concatenate Inputs selected is a 1D array, where A and B are concatenated. The output of Build Array with Concatenate Inputs unselected is a 2D array, where A and B are individual rows in the 2D array.

 


If you have a multi-dimensional array and want to convert it into a one dimensional array, then you need to use a Reshape Array function, which will take the sum of all the elements as the dimension size input. 

Another way of building a custom, one dimensional array from multiple arrays is by using the Insert Into Array function. When you wire an array to this function, the function resizes automatically to display index inputs for each dimension in the array. If you do not wire any index inputs, the function appends the new element or subarray to the end of the n-dim array.

Additional Information

The Build Array function may output a transposed array depending on the inputs. If necessary, Transpose 2D Array function can be used to rearrange the array elements.

If you are using the Build Array function with Concatenate Inputs disabled, and the input arrays are of different dimensions, shorter arrays will be padded with 0s to match the length of the longest input array. For more information, refer to Build Array Function from the LabVIEW Help.